Skip to content

Commit

Permalink
Update highlighter library
Browse files Browse the repository at this point in the history
  • Loading branch information
tobil4sk committed Jul 31, 2024
1 parent 9a34fd4 commit ba36f05
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion highlighting.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-cp src
-main Highlighting
-lib hxnodejs
-lib highlighter:0.6.1
-lib highlighter
-js bin/patch.js
-cmd node bin/patch.js
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "code-cookbook",
"version": "0.1.0",
"devDependencies": {
"vscode-textmate": "3.1.5",
"cson-parser": "3.0.0"
"cson-parser": "3.0.0",
"vscode-oniguruma": "^2.0.1",
"vscode-textmate": "^9.1.0"
}
}
45 changes: 21 additions & 24 deletions src/Highlighting.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,30 @@ class Highlighting {
// Convert CSON grammar to json for vscode-textmate
File.saveContent("bin/javascript.json", Json.stringify(CSON.parse(File.getContent("grammars/language-javascript/grammars/javascript.cson"))));

var haxeGrammar = new Highlighter("grammars/haxe-TmLanguage/haxe.tmLanguage");
var hxmlGrammar = new Highlighter("grammars/haxe-TmLanguage/hxml.tmLanguage");
var xmlGrammar = new Highlighter("grammars/xml.tmbundle/Syntaxes/XML.plist");
var jsGrammar = new Highlighter("bin/javascript.json");

var grammars = [
"haxe" => haxeGrammar,
"hxml" => hxmlGrammar,
"html" => xmlGrammar,
"js" => jsGrammar,
"javascript" => jsGrammar,
var grammarFiles = [
"haxe" => "grammars/haxe-TmLanguage/haxe.tmLanguage",
"hxml" => "grammars/haxe-TmLanguage/hxml.tmLanguage",
"html" => "grammars/xml.tmbundle/Syntaxes/XML.plist",
"js" => "bin/javascript.json",
"javascript" => "bin/javascript.json",
];

// Go over the generated HTML file and apply syntax highlighting
var missingGrammars = Highlighter.patchFolder(Config.outputPath, grammars, function (classList) {
return classList.substr(12);
Highlighter.loadHighlighters(grammarFiles, function(highlighters) {
// Go over the generated HTML file and apply syntax highlighting
var missingGrammars = Highlighter.patchFolder(Config.outputPath, highlighters, function(classList) {
return classList.substr(12);
});

for (g in missingGrammars) {
Sys.println('Missing grammar for "${g}"');
}

// Add CSS rules for highlighting
var path = Config.outputPath + "/css/haxe-nav.min.css";
var baseStyle = File.getContent(path);
var syntaxStyle = highlighters["haxe"].runCss();
File.saveContent(path, baseStyle + syntaxStyle);
});

for (g in missingGrammars) {
Sys.println('Missing grammar for "${g}"');
}

// Add CSS rules for highlighting
var path = Config.outputPath + "/css/haxe-nav.min.css";
var baseStyle = File.getContent(path);
var syntaxStyle = haxeGrammar.runCss();
File.saveContent(path, baseStyle + syntaxStyle);
}
}

Expand Down

0 comments on commit ba36f05

Please sign in to comment.