Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: remove shiki (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
kratico authored Jun 8, 2023
1 parent db9af46 commit 4d762e3
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 84 deletions.
4 changes: 0 additions & 4 deletions _tasks/dnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ await Promise.all([
name: "@substrate/smoldot-light",
version: "0.7.6",
},
"https://esm.sh/v113/[email protected]?bundle": {
name: "shiki",
version: "0.14.1",
},
"./deps/shims/ws.ts": {
name: "ws",
version: "8.13.0",
Expand Down
26 changes: 0 additions & 26 deletions deps/shiki.ts

This file was deleted.

2 changes: 1 addition & 1 deletion import_map.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"imports": {
"@capi/": "http://localhost:4646/a6371dd9c3e070f3/"
"@capi/": "http://localhost:4646/371568ef82e78f0c/"
},
"scopes": {
"examples/": {
Expand Down
54 changes: 1 addition & 53 deletions server/factories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { escapeHtml } from "../deps/escape.ts"
import { highlighterPromise } from "../deps/shiki.ts"
import { Status } from "../deps/std/http.ts"
import { CacheBase } from "../util/cache/base.ts"

Expand Down Expand Up @@ -57,59 +55,9 @@ export function acceptsHtml(request: Request): boolean {
}

export async function renderCode(code: string) {
const highlighter = await highlighterPromise
const tokens = highlighter.codeToThemedTokens(code, "ts")
let codeContent = ""
for (const line of tokens) {
codeContent += `<span class="line">`
for (const token of line) {
if (
token.explanation?.every((value) =>
value.scopes.some((scope) =>
scope.scopeName === "meta.export.ts" || scope.scopeName === "meta.import.ts"
)
&& value.scopes.some((scope) => scope.scopeName === "string.quoted.double.ts")
)
) {
codeContent += `<a style="color: ${token.color}" href="${
escapeHtml(JSON.parse(token.content))
}">${escapeHtml(token.content)}</a>`
} else {
codeContent += `<span style="color: ${token.color}">${escapeHtml(token.content)}</span>`
}
}
codeContent += "</span>\n"
}
const STYLE = `body {
color: ${highlighter.getForegroundColor()};
background-color: ${highlighter.getBackgroundColor()};
}
.shiki {
counter-reset: line;
counter-increment: line 0;
}
.shiki .line::before {
content: counter(line);
counter-increment: line;
width: 5ch;
margin-right: 2ch;
display: inline-block;
text-align: right;
color: rgba(115,138,148,.4)
}
a {
text-decoration-color: transparent;
transition: text-decoration-color .2s;
text-underline-offset: 2px;
}
a:hover {
text-decoration-color: currentColor;
}
`
return `
<style>${STYLE}</style>
<body>
<pre class="shiki"><code>${codeContent}</code></pre>
<pre>${code}</pre>
</body>
`
}

0 comments on commit 4d762e3

Please sign in to comment.