How to highlight JSON in code block macro
プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。
このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
要約
As described in Code Block Macro, you can add new language highlighting to Code Block macro.
Language files must be correctly formatted JavaScript files and adhere to the Custom Brush syntax
Add New Language removed
Please note that with Confluence 8.9.4 and later, the Add New Language option has been removed to improve platform security and performance.
If you haven’t installed any custom languages, this change won’t affect you.
If you’ve installed custom languages, they will stop working, and code blocks using them will revert to the default language. Java becomes the default for code blocks previously set to a custom language. See also Confluence Release Notes
環境
Confluence 7.x、8.x
ソリューション
Save below code as JavaScript (*.js) file and add it to Confluence following instructions from Code Block Macro page
- > [コード マクロの設定] の順に選択します。 > [一般設定]
- [新規言語の追加] を選択します。
- 追加する言語ファイルを見つけ、新しい言語の [名前] を入力します (これは言語の選択時に表示されます)。
- 追加を選択します。
;(function()
{
// CommonJS
SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
function Brush()
{
var keywords = 'false true null';
this.regexList = [
{ regex: /"([^\\"\n]|\\.)*"(?=:)/g, css: 'string' }, // strings
{ regex: /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/g, css: 'number' }, // number
{ regex: /"([^\\"\n]|\\.)*"/g, css: 'value' }, // value
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' } // keyword
];
this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
};
Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['json'];
SyntaxHighlighter.brushes.Json = Brush;
// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();
How to remove any custom language added
After following the steps described above, you should see a new app listed in the 'User Installed' section of the 'Manage Apps' screen:
From there, you can disable the app temporarily or remove it totally to remove the highlighting functionality for specific custom language.