10000 Async Prism highlighting by Alex-Tideman · Pull Request #1337 · temporalio/ui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Async Prism highlighting #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ declare module '@sveltejs/svelte-virtual-list';
interface Window {
Prism: {
highlightAll: () => void;
highlightElement: (element: Element) => void;
highlightElement: (
element: Element,
async?: boolean,
highlightCallback?: () => void,
) => void;
};
}
3 changes: 2 additions & 1 deletion src/lib/holocene/code-block.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export let inline = false;
export let language = 'json';
export let copyable = true;
export let async = true;

let root: HTMLElement;
$: isJSON = language === 'json';
Expand Down Expand Up @@ -37,7 +38,7 @@
root.classList.add(`language-${language}`);
}

window.Prism.highlightElement(root);
window.Prism.highlightElement(root, async);
}

$: {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/vendor/prism/prism.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,15 @@ var _self =
return M.hooks.run('complete', l), void (t && t.call(l.element));
if ((M.hooks.run('before-highlight', l), l.grammar))
if (n && u.Worker) {
var s = new Worker(M.filename);
const filename =
M.filename ??
`${window.location.origin}/src/lib/vendor/prism/prism.cjs`;
var s = new Worker(filename);

s. () {
o(M.highlight(l.code, l.grammar, l.language));
};

(s. (e) {
o(e.data);
}),
Expand Down
0