Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to mention https://github.com/syntaxhighlighter/brush-typescript (MIT licensed)

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"];