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

  1.  > [一般設定] > [コード マクロの設定] の順に選択します。
  2. [新規言語の追加] を選択します。
  3. 追加する言語ファイルを見つけ、新しい言語の [名前] を入力します (これは言語の選択時に表示されます)。
  4. 追加を選択します。
JSON Code Block highlight
;(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;
})();

最終更新日: 2022 年 2 月 9 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.