Skip to content

Commit adc52e2

Browse files
authored
Merge pull request #129 from candrews/yaml
YAML Highlighter
2 parents 2562939 + ccf4f8e commit adc52e2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

syntaxhighlighter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
144144
wp_register_script( 'syntaxhighlighter-brush-sql', plugins_url( $this->shfolder . '/scripts/shBrushSql.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
145145
wp_register_script( 'syntaxhighlighter-brush-vb', plugins_url( $this->shfolder . '/scripts/shBrushVb.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
146146
wp_register_script( 'syntaxhighlighter-brush-xml', plugins_url( $this->shfolder . '/scripts/shBrushXml.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
147+
wp_register_script( 'syntaxhighlighter-brush-yaml', plugins_url( $this->shfolder . '/scripts/shBrushYaml.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
147148

148149
// Register some popular third-party brushes
149150
wp_register_script( 'syntaxhighlighter-brush-clojure', plugins_url( 'third-party-brushes/shBrushClojure.js', __FILE__ ), array('syntaxhighlighter-core'), '20090602' );
@@ -224,6 +225,8 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
224225
'xhtml' => 'xml',
225226
'xslt' => 'xml',
226227
'html' => 'xml',
228+
'yaml' => 'yaml',
229+
'yml' => 'yaml',
227230
) );
228231

229232
$this->brush_names = (array) apply_filters( 'syntaxhighlighter_brush_names', array(
@@ -256,6 +259,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
256259
'sql' => __( 'SQL', 'syntaxhighlighter' ),
257260
'vb' => __( 'Visual Basic', 'syntaxhighlighter' ),
258261
'xml' => __( 'HTML / XHTML / XML / XSLT', 'syntaxhighlighter' ),
262+
'yaml' => __( 'YAML', 'syntaxhighlighter' ),
259263
) );
260264

261265
// Add any custom brushes that aren't making use of the newer "syntaxhighlighter_brush_names" filter.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* SyntaxHighlighter
3+
* http://alexgorbatchev.com/SyntaxHighlighter
4+
*
5+
* SyntaxHighlighter is donationware. If you are using it, please donate.
6+
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
7+
*
8+
* @copyright
9+
* Copyright (C) 2019 Craig Andrews.
10+
* Copyright (C) 2016 Erik Wegner.
11+
*
12+
* @license
13+
* Dual licensed under the MIT and GPL licenses.
14+
*/
15+
;(function()
16+
{
17+
// CommonJS
18+
SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
19+
20+
function Brush()
21+
{
22+
23+
// Yaml Brush
24+
25+
var constants = '~ true false on off';
26+
27+
this.regexList = [
28+
{ regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' }, // comment
29+
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted string
30+
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // single quoted string
31+
{ regex: /^\s*([a-z0-9\._-])+\s*:/gmi, css: 'variable' }, // key
32+
{ regex: /\s?(\.)([a-z0-9\._-])+\s?:/gmi, css: 'comments' }, // section
33+
{ regex: /\s(@|:)([a-z0-9\._-])+\s*$/gmi, css: 'variable bold' }, // variable, reference
34+
{ regex: /\s+\d+\s?$/gm, css: 'color2 bold' }, // integers
35+
{ regex: /(\{|\}|\[|\]|,|~|:)/gm, css: 'constants' }, // inline hash and array, comma, null
36+
{ regex: /^\s+(-)+/gm, css: 'string bold' }, // array list entry
37+
{ regex: /^---/gm, css: 'string bold' }, // category
38+
{ regex: new RegExp(this.getKeywords(constants), 'gmi'), css: 'constants' } // constants
39+
];
40+
41+
this.forHtmlScript(SyntaxHighlighter.regexLib.phpScriptTags);
42+
}
43+
Brush.prototype = new SyntaxHighlighter.Highlighter();
44+
Brush.aliases = ['yaml', 'yml'];
45+
46+
SyntaxHighlighter.brushes.Yaml = Brush;
47+
48+
// CommonJS
49+
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
50+
})();

0 commit comments

Comments
 (0)