use the new highlighter in all the pages

This commit is contained in:
Araozu 2024-03-27 12:01:14 -05:00
parent d098b60a38
commit b78b30a34d
5 changed files with 28 additions and 55 deletions

View File

@ -36,9 +36,6 @@ export function lex(code: string): Array<Token> {
while (current_pos < code_len) {
const c = code[current_pos];
let next_token: Token | null = null;
let next_position: number | null = null;
// try to scan a number
if (is_digit(c)) {
// if the current default token is not empty, push it to the tokens array
@ -118,25 +115,15 @@ export function lex(code: string): Array<Token> {
current_pos = pos;
continue;
}
// here, check if a token was found
if (next_token !== null && next_position !== null) {
// if there was a default token, push it to the tokens array
if (current_default_token !== "") {
tokens.push({ v: current_default_token, token_type: "" });
current_default_token = "";
}
// then push the new token found
tokens.push(next_token);
current_pos = next_position;
// replace < with &lt;
else if (c === "<") {
current_default_token += "&lt;";
current_pos++;
continue;
}
// otherwise, add the current character to the default token
else {
current_default_token += c;
current_pos++;
}
current_default_token += c;
current_pos++;
}
// if there was a default token, push it to the tokens array

View File

@ -74,8 +74,6 @@
</div>
</div>
<script src="/js/prism.min.js"></script>
<script src="/js/prism.thp.js"></script>
<script src="/js/highlighter.js"></script>
<script>
let jar = CodeJar(document.getElementById("editor"), thp_highlighter, {
@ -83,7 +81,7 @@
});
jar.updateCode(
`// Actual generics & sum types 322 644
`// Actual generics & sum types
fun find_person(Int person_id) -> Result[String, String] {
// Easy, explicit error bubbling
try Person::find_by_id(person_id)

File diff suppressed because one or more lines are too long

View File

@ -1,25 +0,0 @@
Prism.languages.thp = {
"comment": [
{
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
lookbehind: true,
greedy: true,
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true,
},
],
"string": {
pattern: /(["])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
greedy: true,
},
"keyword": /\b(?:case|static|const|enum|loop|use|break|catch|continue|do|else|finally|for|fun|if|in|fn|nil|return|throw|try|while|type|match|with|of|abstract|class|interface|private|pub|map|override|open|init|val|var|mut|clone)\b/,
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
"operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/,
"punctuation": /[{}[\];(),.]/,
"boolean": /\b(?:false|true)\b/,
"class-name": /\b[A-Z][a-zA-Z_0-9]*\b/,
"variable": /\b[a-z_0-9][a-zA-Z_0-9]+:/,
};

View File

@ -49,8 +49,25 @@
</main>
</div>
<script src="/js/prism.min.js"></script>
<script src="/js/prism.thp.js"></script>
</body>
<script src="/js/highlighter.js"></script>
<script>
// Add an editor to all code samples
const code_elements = document.querySelectorAll(".language-thp");
for (const el of [...code_elements]) {
const pre_parent = el.parentElement;
const new_div = document.createElement("div");
const code = el.innerHTML;
el.parentElement.classList.add("language-thp");
pre_parent.removeChild(el);
pre_parent.appendChild(new_div);
CodeJar(new_div, thp_highlighter, {
tab: " "
}).updateCode(code);
}
</script>
</body>
</html>