Skip to content

Commit

Permalink
Merge pull request #129 from candrews/yaml
Browse files Browse the repository at this point in the history
YAML Highlighter
  • Loading branch information
renatho committed Apr 6, 2020
2 parents 2562939 + ccf4f8e commit adc52e2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions syntaxhighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
wp_register_script( 'syntaxhighlighter-brush-sql', plugins_url( $this->shfolder . '/scripts/shBrushSql.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
wp_register_script( 'syntaxhighlighter-brush-vb', plugins_url( $this->shfolder . '/scripts/shBrushVb.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
wp_register_script( 'syntaxhighlighter-brush-xml', plugins_url( $this->shfolder . '/scripts/shBrushXml.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
wp_register_script( 'syntaxhighlighter-brush-yaml', plugins_url( $this->shfolder . '/scripts/shBrushYaml.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );

// Register some popular third-party brushes
wp_register_script( 'syntaxhighlighter-brush-clojure', plugins_url( 'third-party-brushes/shBrushClojure.js', __FILE__ ), array('syntaxhighlighter-core'), '20090602' );
Expand Down Expand Up @@ -224,6 +225,8 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
'xhtml' => 'xml',
'xslt' => 'xml',
'html' => 'xml',
'yaml' => 'yaml',
'yml' => 'yaml',
) );

$this->brush_names = (array) apply_filters( 'syntaxhighlighter_brush_names', array(
Expand Down Expand Up @@ -256,6 +259,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
'sql' => __( 'SQL', 'syntaxhighlighter' ),
'vb' => __( 'Visual Basic', 'syntaxhighlighter' ),
'xml' => __( 'HTML / XHTML / XML / XSLT', 'syntaxhighlighter' ),
'yaml' => __( 'YAML', 'syntaxhighlighter' ),
) );

// Add any custom brushes that aren't making use of the newer "syntaxhighlighter_brush_names" filter.
Expand Down
50 changes: 50 additions & 0 deletions syntaxhighlighter3/scripts/shBrushYaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @copyright
* Copyright (C) 2019 Craig Andrews.
* Copyright (C) 2016 Erik Wegner.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
;(function()
{
// CommonJS
SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);

function Brush()
{

// Yaml Brush

var constants = '~ true false on off';

this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' }, // comment
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted string
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // single quoted string
{ regex: /^\s*([a-z0-9\._-])+\s*:/gmi, css: 'variable' }, // key
{ regex: /\s?(\.)([a-z0-9\._-])+\s?:/gmi, css: 'comments' }, // section
{ regex: /\s(@|:)([a-z0-9\._-])+\s*$/gmi, css: 'variable bold' }, // variable, reference
{ regex: /\s+\d+\s?$/gm, css: 'color2 bold' }, // integers
{ regex: /(\{|\}|\[|\]|,|~|:)/gm, css: 'constants' }, // inline hash and array, comma, null
{ regex: /^\s+(-)+/gm, css: 'string bold' }, // array list entry
{ regex: /^---/gm, css: 'string bold' }, // category
{ regex: new RegExp(this.getKeywords(constants), 'gmi'), css: 'constants' } // constants
];

this.forHtmlScript(SyntaxHighlighter.regexLib.phpScriptTags);
}
Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['yaml', 'yml'];

SyntaxHighlighter.brushes.Yaml = Brush;

// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();

0 comments on commit adc52e2

Please sign in to comment.