Skip to content

Commit

Permalink
Add TypeScript syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Oct 27, 2022
1 parent 13989ac commit 011f801
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions syntaxhighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
wp_register_script( 'syntaxhighlighter-brush-matlabkey', plugins_url( 'third-party-brushes/shBrushMatlabKey.js', __FILE__ ), array( 'syntaxhighlighter-core' ), '20091209' );
wp_register_script( 'syntaxhighlighter-brush-objc', plugins_url( 'third-party-brushes/shBrushObjC.js', __FILE__ ), array( 'syntaxhighlighter-core' ), '20091207' );
wp_register_script( 'syntaxhighlighter-brush-r', plugins_url( 'third-party-brushes/shBrushR.js', __FILE__ ), array( 'syntaxhighlighter-core' ), '20100919' );
wp_register_script( 'syntaxhighlighter-brush-ts', plugins_url( 'third-party-brushes/shBrushTs.js', __FILE__ ), array( 'syntaxhighlighter-core' ), '20160926' );

// Register theme stylesheets
wp_register_style( 'syntaxhighlighter-core', plugins_url( $this->shfolder . '/styles/shCore.css', __FILE__ ), array(), $this->agshver );
Expand Down Expand Up @@ -231,6 +232,8 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
'rb' => 'ruby',
'ror' => 'ruby',
'ruby' => 'ruby',
'ts' => 'ts',
'typescript' => 'ts',
'scala' => 'scala',
'sql' => 'sql',
'swift' => 'swift',
Expand Down Expand Up @@ -277,6 +280,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
'scala' => __( 'Scala', 'syntaxhighlighter' ),
'swift' => __( 'Swift', 'syntaxhighlighter' ),
'sql' => __( 'SQL', 'syntaxhighlighter' ),
'ts' => __( 'TypeScript', 'syntaxhighlighter' ),
'vb' => __( 'Visual Basic', 'syntaxhighlighter' ),
'xml' => __( 'HTML / XHTML / XML / XSLT', 'syntaxhighlighter' ),
'yaml' => __( 'YAML', 'syntaxhighlighter' ),
Expand Down
38 changes: 38 additions & 0 deletions third-party-brushes/shBrushTs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
SyntaxHighlighter.brushes.ts = function () {
const keywords =
"break case catch class continue " +
"default delete do else enum export extends false " +
"for function if implements import in instanceof " +
"interface let new null package private protected " +
"static return super switch " +
"this throw true try typeof var while with yield" +
" any bool declare get module never number public readonly set string"; // TypeScript-specific, everything above is common with JavaScript

this.regexList = [
{
regex: SyntaxHighlighter.regexLib.multiLineDoubleQuotedString,
css: "string",
},
{
regex: SyntaxHighlighter.regexLib.multiLineSingleQuotedString,
css: "string",
},
{
regex: SyntaxHighlighter.regexLib.singleLineCComments,
css: "comments",
},
{
regex: SyntaxHighlighter.regexLib.multiLineCComments,
css: "comments",
},
{
regex: new RegExp(this.getKeywords(keywords), "gm"),
css: "keyword",
},
];

this.forHtmlScript(SyntaxHighlighter.regexLib.scriptScriptTags);
};

SyntaxHighlighter.brushes.ts.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.ts.aliases = ["ts", "typescript"];

0 comments on commit 011f801

Please sign in to comment.