From 5208496124f204c48307dac13209ecf3d1c234f8 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 4 Jul 2024 20:20:24 -0500 Subject: [PATCH] Fix highlighter. Add docs on templating --- src/components/CodeEditor.astro | 10 ++- src/components/InteractiveCode.astro | 61 ++++++++++----- src/layouts/thpHighlighter.ts | 5 +- src/lexer/lexer.ts | 32 +++++++- src/pages/index.astro | 16 ++-- src/pages/learn/basics/comments.md | 16 +++- src/pages/learn/basics/hello-world.mdx | 32 +++++++- src/pages/learn/basics/variables.md | 16 ++-- src/pages/learn/index.mdx | 21 ++--- src/pages/learn/install.md | 2 + src/pages/learn/templating/intro.md | 104 +++++++++++++++++++++++++ 11 files changed, 263 insertions(+), 52 deletions(-) create mode 100644 src/pages/learn/templating/intro.md diff --git a/src/components/CodeEditor.astro b/src/components/CodeEditor.astro index 0874cec..d6c620e 100644 --- a/src/components/CodeEditor.astro +++ b/src/components/CodeEditor.astro @@ -1,11 +1,13 @@ --- import { trimAndDedent } from "./utils"; -const {thpcode} = Astro.props; +const { thpcode } = Astro.props; ---
-
-
{trimAndDedent(thpcode).join("\n")}
-
+
+
{trimAndDedent(thpcode).join("\n")}
+
diff --git a/src/components/InteractiveCode.astro b/src/components/InteractiveCode.astro index 3b62e89..d980a57 100644 --- a/src/components/InteractiveCode.astro +++ b/src/components/InteractiveCode.astro @@ -3,8 +3,7 @@ import { lex } from "../lexer/lexer"; import type { Instruction } from "../thp_machine/machine_parser"; import { parse_str } from "../thp_machine/machine_parser"; import { trimAndDedent } from "./utils"; -const {code, steps} = Astro.props; - +const { code, steps } = Astro.props; function highlightCode(lines: Array): string { let outLines: Array = []; @@ -12,12 +11,14 @@ function highlightCode(lines: Array): string { for (const [idx, line] of lines.entries()) { const tokens = lex(line); const lineArray = [ - `
` + `
`, ]; for (const token of tokens) { if (token.token_type !== "") { - lineArray.push(`${token.v}`); + lineArray.push( + `${token.v}`, + ); } else { lineArray.push(token.v); } @@ -42,7 +43,8 @@ try { const serialized_inst = JSON.stringify(instructionSet); --- -
- thp code -
+ thp code +
stdout
-
+
state
- -