How to highlight JSON in code block macro
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*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
ソリューション
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.