Skip to content

Commit

Permalink
Update highlighter library (#472)
Browse files Browse the repository at this point in the history
* Update highlighter library

* [earthly] Update earthly image

focal has a node version that is too old

* Update readme setup info

We no longer need an ancient version of node for vscode-textmate

* Show generator complete message only when complete
  • Loading branch information
tobil4sk authored Aug 2, 2024
1 parent 3b1a34e commit 59b2587
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION 0.6
FROM ubuntu:focal
FROM ubuntu:noble
WORKDIR /workspace
RUN apt-get update \
&& apt-get install -qqy --no-install-recommends \
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,11 @@ The haxe.org website was designed to be easy to generate, to run a local copy fo
* Haxelib
* Neko
* cUrl
* NodeJS 10 (via `nvm`: <https://github.com/nvm-sh/nvm>)
* NodeJS
* npm

### Setting up

* Set up node using nvm:

```sh
nvm install 10
npm config set node_gyp $(npm prefix -g)/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js
```

* Install the dependencies `haxelib install all` and `npm install` in the root directory.
* Update submodule dependencies `git submodule init && git submodule update`.
* Clone the manual into the `manual` directory with `git clone https://github.com/HaxeFoundation/HaxeManual.git manual`.
Expand Down
80 changes: 53 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "haxe-website",
"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"
}
}
8 changes: 4 additions & 4 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Main {
generators.RobotsTxt.generate();

// Patch as post process the html file with syntax highlighting
SyntaxHighlighter.patch();

var end = Date.now().getTime();
Sys.println('Generation complete, time ${(end - start)/1000}s');
SyntaxHighlighter.patch(function () {
var end = Date.now().getTime();
Sys.println('Generation complete, time ${(end - start) / 1000}s');
});
}

}
68 changes: 30 additions & 38 deletions src/SyntaxHighlighter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,46 @@ import sys.io.File;

class SyntaxHighlighter
{
public static function patch () {
public static function patch (onComplete:()->Void) {
Sys.println("Applying syntax 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"))));
File.saveContent("bin/shell-unix-bash.json", Json.stringify(CSON.parse(File.getContent("grammars/language-shellscript/grammars/shell-unix-bash.cson"))));

var haxeGrammar = new Highlighter("grammars/haxe-TmLanguage/haxe.tmLanguage");
var hxmlGrammar = new Highlighter("grammars/haxe-TmLanguage/hxml.tmLanguage");
var luaGrammar = new Highlighter("grammars/lua.tmbundle/Syntaxes/Lua.plist");
var xmlGrammar = new Highlighter("grammars/xml.tmbundle/Syntaxes/XML.plist");
var cppGrammar = new Highlighter("grammars/c.tmbundle/Syntaxes/C++.plist");
var as3Grammar = new Highlighter("grammars/actionscript3-tmbundle/Syntaxes/ActionScript 3.tmLanguage");
var pythonGrammar = new Highlighter("grammars/python.tmbundle/Syntaxes/Python.tmLanguage");
var javaGrammar = new Highlighter("grammars/Java.plist"); // from https://github.com/textmate/java.tmbundle
var ocamlGrammar = new Highlighter("grammars/OCaml.plist"); // from https://github.com/textmate/ocaml.tmbundle
var jsGrammar = new Highlighter("bin/javascript.json");
var shGrammar = new Highlighter("bin/shell-unix-bash.json");

var grammars = [
"haxe" => haxeGrammar,
"hxml" => hxmlGrammar,
"lua" => luaGrammar,
"xml" => xmlGrammar,
"cpp" => cppGrammar,
"as3" => as3Grammar,
"python" => pythonGrammar,
"js" => jsGrammar,
"java" => javaGrammar,
"ocaml" => ocamlGrammar,
"javascript" => jsGrammar,
"sh" => shGrammar,
var grammarFiles = [
"haxe" => "grammars/haxe-TmLanguage/haxe.tmLanguage",
"hxml" => "grammars/haxe-TmLanguage/hxml.tmLanguage",
"lua" => "grammars/lua.tmbundle/Syntaxes/Lua.plist",
"xml" => "grammars/xml.tmbundle/Syntaxes/XML.plist",
"cpp" => "grammars/c.tmbundle/Syntaxes/C++.plist",
"as3" => "grammars/actionscript3-tmbundle/Syntaxes/ActionScript 3.tmLanguage",
"python" => "grammars/python.tmbundle/Syntaxes/Python.tmLanguage",
"js" => "bin/javascript.json",
"javascript" => "bin/javascript.json",
"java" => "grammars/Java.plist", // from https://github.com/textmate/java.tmbundle
"ocaml" => "grammars/OCaml.plist", // from https://github.com/textmate/ocaml.tmbundle
"sh" => "bin/shell-unix-bash.json",
];

// Go over the generated HTML file and apply syntax highlighting
var missingGrammars = Highlighter.patchFolder(Config.outputFolder, 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.outputFolder, highlighters, function(classList) {
return classList.substr(12);}
);

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

for (g in missingGrammars) {
Sys.println('Missing grammar for "${g}"');
}
// Add CSS rules for highlighting
var path = Config.outputFolder + "/css/style.css";
var baseStyle = File.getContent(path);
var syntaxStyle = highlighters["haxe"].runCss();
File.saveContent(path, baseStyle + syntaxStyle);

// Add CSS rules for highlighting
var path = Config.outputFolder + "/css/style.css";
var baseStyle = File.getContent(path);
var syntaxStyle = haxeGrammar.runCss();
File.saveContent(path, baseStyle + syntaxStyle);
onComplete();
});
}
}

Expand Down

0 comments on commit 59b2587

Please sign in to comment.