-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e0f4a3
commit b8a80fc
Showing
20 changed files
with
1,470 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
import { spanHighlight } from './js/tokenizer-highlighter'; | ||
import { dusaTokenizer } from './js/dusa-tokenizer'; | ||
function trimSlightly(code: string): string { | ||
const code2 = | ||
code[0] === '\n' && code[1] === '\n' ? code.slice(2) : code[0] === '\n' ? code.slice(1) : code; | ||
return code2[code2.length - 2] === '\n' && code2[code2.length - 1] === '\n' | ||
? code2.slice(0, code2.length - 2) | ||
: code2[code.length - 1] === '\n' | ||
? code2.slice(0, code2.length - 1) | ||
: code2; | ||
} | ||
function htmlEscape(code: string) { | ||
return code.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'); | ||
} | ||
const highlightedCode = spanHighlight( | ||
dusaTokenizer( | ||
(Astro.props.predicates ?? []), | ||
(Astro.props.builtins ?? []), | ||
), | ||
trimSlightly(Astro.props.code ?? ''), | ||
) | ||
.map((line) => { | ||
const htmlLine = line.map(({ tag, contents }) => { | ||
if (tag) { | ||
return `<span class="tok-${tag}">${htmlEscape(contents)}</span>`; | ||
} else { | ||
return htmlEscape(contents); | ||
} | ||
}); | ||
return `${htmlLine.join('')}`; | ||
}) | ||
.join('\n'); | ||
--- | ||
|
||
<div class="container"> | ||
<pre class="dusa" set:html={highlightedCode} /> | ||
</div> | ||
|
||
<style> | ||
.container { | ||
background-color: var(--editor-background); | ||
color: var(--editor-text); | ||
} | ||
|
||
.container pre { | ||
font-family: var(--sl-font-mono); | ||
line-height: 1.4; | ||
font-weight: 600; | ||
} | ||
</style> |
Oops, something went wrong.