mirror of
https://github.com/typst/typst
synced 2025-08-21 10:18:35 +08:00
Compare commits
27 Commits
ff1d4ded4a
...
76ba9f4503
Author | SHA1 | Date | |
---|---|---|---|
|
76ba9f4503 | ||
|
85458e555b | ||
|
8055ecc769 | ||
|
d6fea42984 | ||
|
ad9fc0cafb | ||
|
fa6d5f2c51 | ||
|
40f3b7756c | ||
|
9f0b320729 | ||
|
40b438e1ec | ||
|
0de83dbb05 | ||
|
1d90860357 | ||
|
298835e6fe | ||
|
5c44d2222a | ||
|
45759253d3 | ||
|
67f9b04617 | ||
|
1bf8c37a19 | ||
|
bcf40aa755 | ||
|
53e3d50611 | ||
|
d982bdba49 | ||
|
3d36f75e86 | ||
|
761ae38fcd | ||
|
8ee990c453 | ||
|
a80502a110 | ||
|
6f18f28a21 | ||
|
f3810dd36a | ||
|
6eaa12fab8 | ||
|
41b57697d9 |
21
README.md
21
README.md
@ -240,26 +240,6 @@ instant preview. To achieve these goals, we follow three core design principles:
|
||||
Luckily we have [`comemo`], a system for incremental compilation which does
|
||||
most of the hard work in the background.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
We'd like to thank everyone who is supporting Typst's development, be it via
|
||||
[GitHub sponsors] or elsewhere. In particular, special thanks[^1] go to:
|
||||
|
||||
- [Posit](https://posit.co/blog/posit-and-typst/) for financing a full-time
|
||||
compiler engineer
|
||||
- [NLnet](https://nlnet.nl/) for supporting work on Typst via multiple grants
|
||||
through the [NGI Zero Core](https://nlnet.nl/core) fund:
|
||||
- Work on [HTML export](https://nlnet.nl/project/Typst-HTML/)
|
||||
- Work on [PDF accessibility](https://nlnet.nl/project/Typst-Accessibility/)
|
||||
- [Science & Startups](https://www.science-startups.berlin/) for having financed
|
||||
Typst development from January through June 2023 via the Berlin Startup
|
||||
Scholarship
|
||||
- [Zerodha](https://zerodha.tech/blog/1-5-million-pdfs-in-25-minutes/) for their
|
||||
generous one-time sponsorship
|
||||
|
||||
[^1]: This list only includes contributions for our open-source work that exceed
|
||||
or are expected to exceed €10K.
|
||||
|
||||
[docs]: https://typst.app/docs/
|
||||
[app]: https://typst.app/
|
||||
[discord]: https://discord.gg/2uDybryKPe
|
||||
@ -279,4 +259,3 @@ We'd like to thank everyone who is supporting Typst's development, be it via
|
||||
[packages]: https://github.com/typst/packages/
|
||||
[`comemo`]: https://github.com/typst/comemo/
|
||||
[snap]: https://snapcraft.io/typst
|
||||
[GitHub sponsors]: https://github.com/sponsors/typst/
|
||||
|
@ -498,7 +498,7 @@ pub enum PdfStandard {
|
||||
/// PDF/A-2u.
|
||||
#[value(name = "a-2u")]
|
||||
A_2u,
|
||||
/// PDF/A-3b.
|
||||
/// PDF/A-3u.
|
||||
#[value(name = "a-3b")]
|
||||
A_3b,
|
||||
/// PDF/A-3u.
|
||||
|
@ -1284,18 +1284,10 @@ impl<'a> GridLayouter<'a> {
|
||||
if let Some([first, rest @ ..]) =
|
||||
frames.get(measurement_data.frames_in_previous_regions..)
|
||||
{
|
||||
// HACK: reconsider if this is the right decision
|
||||
fn is_empty_frame(frame: &Frame) -> bool {
|
||||
!frame.items().any(|(_, item)| match item {
|
||||
FrameItem::Group(group) => is_empty_frame(&group.frame),
|
||||
FrameItem::Tag(_) => false,
|
||||
_ => true,
|
||||
})
|
||||
}
|
||||
if can_skip
|
||||
&& breakable
|
||||
&& is_empty_frame(first)
|
||||
&& rest.iter().any(|frame| !is_empty_frame(frame))
|
||||
&& first.is_empty()
|
||||
&& rest.iter().any(|frame| !frame.is_empty())
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
|
@ -604,7 +604,7 @@ impl Array {
|
||||
Ok(acc)
|
||||
}
|
||||
|
||||
/// Calculates the product of all items (works for all types that can be
|
||||
/// Calculates the product all items (works for all types that can be
|
||||
/// multiplied).
|
||||
#[func]
|
||||
pub fn product(
|
||||
|
@ -207,9 +207,9 @@ pub fn sqrt(
|
||||
/// ```
|
||||
#[func]
|
||||
pub fn root(
|
||||
/// The expression to take the root of.
|
||||
/// The expression to take the root of
|
||||
radicand: f64,
|
||||
/// Which root of the radicand to take.
|
||||
/// Which root of the radicand to take
|
||||
index: Spanned<i64>,
|
||||
) -> SourceResult<f64> {
|
||||
if index.v == 0 {
|
||||
@ -317,7 +317,7 @@ pub fn asin(
|
||||
/// ```
|
||||
#[func(title = "Arccosine")]
|
||||
pub fn acos(
|
||||
/// The number whose arccosine to calculate. Must be between -1 and 1.
|
||||
/// The number whose arcsine to calculate. Must be between -1 and 1.
|
||||
value: Spanned<Num>,
|
||||
) -> SourceResult<Angle> {
|
||||
let val = value.v.float();
|
||||
@ -387,7 +387,7 @@ pub fn cosh(
|
||||
value.cosh()
|
||||
}
|
||||
|
||||
/// Calculates the hyperbolic tangent of a hyperbolic angle.
|
||||
/// Calculates the hyperbolic tangent of an hyperbolic angle.
|
||||
///
|
||||
/// ```example
|
||||
/// #calc.tanh(0) \
|
||||
|
@ -817,10 +817,6 @@ pub struct TableCell {
|
||||
// TODO: feature gate
|
||||
pub header_scope: Smart<TableHeaderScope>,
|
||||
|
||||
// FIXME: this should not be public
|
||||
#[default(false)]
|
||||
pub is_repeated: bool,
|
||||
|
||||
/// Whether rows spanned by this cell can be placed in different pages.
|
||||
/// When equal to `{auto}`, a cell spanning only fixed-size rows is
|
||||
/// unbreakable, while a cell spanning at least one `{auto}`-sized row is
|
||||
|
@ -179,7 +179,7 @@ pub enum PdfStandard {
|
||||
/// PDF/A-2u.
|
||||
#[serde(rename = "a-2u")]
|
||||
A_2u,
|
||||
/// PDF/A-3b.
|
||||
/// PDF/A-3u.
|
||||
#[serde(rename = "a-3b")]
|
||||
A_3b,
|
||||
/// PDF/A-3u.
|
||||
|
@ -230,7 +230,7 @@ impl TableCtx {
|
||||
}
|
||||
a
|
||||
})
|
||||
.unwrap_or(TableCellKind::Data)
|
||||
.expect("tables must have at least one column")
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -524,12 +524,7 @@ pub(crate) fn handle_start(gc: &mut GlobalContext, elem: &Content) {
|
||||
push_stack(gc, loc, StackEntryKind::Table(TableCtx::new(table.clone())));
|
||||
return;
|
||||
} else if let Some(cell) = elem.to_packed::<TableCell>() {
|
||||
// TODO: set this in table layout
|
||||
if cell.is_repeated(StyleChain::default()) {
|
||||
start_artifact(gc, loc, ArtifactKind::Other);
|
||||
} else {
|
||||
push_stack(gc, loc, StackEntryKind::TableCell(cell.clone()));
|
||||
}
|
||||
return;
|
||||
} else if let Some(link) = elem.to_packed::<LinkMarker>() {
|
||||
let link_id = gc.tags.next_link_id();
|
||||
|
@ -79,7 +79,7 @@ the right.
|
||||
|
||||
Last but not least is the `numbering` argument. Here, we can provide a
|
||||
[numbering pattern]($numbering) that defines how to number the pages. By
|
||||
setting it to `{"1"}`, Typst only displays the bare page number. Setting it to
|
||||
setting into to `{"1"}`, Typst only displays the bare page number. Setting it to
|
||||
`{"(1/1)"}` would have displayed the current page and total number of pages
|
||||
surrounded by parentheses. And we could even have provided a completely custom
|
||||
function here to format things to our liking.
|
||||
|
@ -94,12 +94,9 @@
|
||||
"watch": "tsc -watch -p ./"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.0.4",
|
||||
"@types/vscode": "^1.101.0",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"shiki": "^3.7.0"
|
||||
"@types/node": "18.x",
|
||||
"@types/vscode": "^1.88.0",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.88.0"
|
||||
|
@ -1,7 +1,6 @@
|
||||
import * as vscode from "vscode";
|
||||
import * as cp from "child_process";
|
||||
import { clearInterval } from "timers";
|
||||
const shiki = import("shiki"); // Normal import causes TypeScript problems.
|
||||
|
||||
// Called when an activation event is triggered. Our activation event is the
|
||||
// presence of "tests/suite/playground.typ".
|
||||
@ -18,8 +17,6 @@ class TestHelper {
|
||||
opened?: {
|
||||
// The tests's name.
|
||||
name: string;
|
||||
// The test's attributes.
|
||||
attrs: string[];
|
||||
// The WebView panel that displays the test images and output.
|
||||
panel: vscode.WebviewPanel;
|
||||
};
|
||||
@ -47,18 +44,18 @@ class TestHelper {
|
||||
);
|
||||
|
||||
// Triggered when clicking "View" in the lens.
|
||||
this.registerCommand("typst-test-helper.viewFromLens", (name, attrs) =>
|
||||
this.viewFromLens(name, attrs)
|
||||
this.registerCommand("typst-test-helper.viewFromLens", (name) =>
|
||||
this.viewFromLens(name)
|
||||
);
|
||||
|
||||
// Triggered when clicking "Run" in the lens.
|
||||
this.registerCommand("typst-test-helper.runFromLens", (name, attrs) =>
|
||||
this.runFromLens(name, attrs)
|
||||
this.registerCommand("typst-test-helper.runFromLens", (name) =>
|
||||
this.runFromLens(name)
|
||||
);
|
||||
|
||||
// Triggered when clicking "Save" in the lens.
|
||||
this.registerCommand("typst-test-helper.saveFromLens", (name, attrs) =>
|
||||
this.saveFromLens(name, attrs)
|
||||
this.registerCommand("typst-test-helper.saveFromLens", (name) =>
|
||||
this.saveFromLens(name)
|
||||
);
|
||||
|
||||
// Triggered when clicking "Terminal" in the lens.
|
||||
@ -124,32 +121,31 @@ class TestHelper {
|
||||
const lenses = [];
|
||||
for (let nr = 0; nr < document.lineCount; nr++) {
|
||||
const line = document.lineAt(nr);
|
||||
const re = /^--- ([\d\w-]+)(( [\d\w-]+)*) ---$/;
|
||||
const re = /^--- ([\d\w-]+)( [\d\w-]+)* ---$/;
|
||||
const m = line.text.match(re);
|
||||
if (!m) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const name = m[1];
|
||||
const attrs = m[2].trim().split(" ");
|
||||
lenses.push(
|
||||
new vscode.CodeLens(line.range, {
|
||||
title: "View",
|
||||
tooltip: "View the test output and reference in a new tab",
|
||||
command: "typst-test-helper.viewFromLens",
|
||||
arguments: [name, attrs],
|
||||
arguments: [name],
|
||||
}),
|
||||
new vscode.CodeLens(line.range, {
|
||||
title: "Run",
|
||||
tooltip: "Run the test and view the results in a new tab",
|
||||
command: "typst-test-helper.runFromLens",
|
||||
arguments: [name, attrs],
|
||||
arguments: [name],
|
||||
}),
|
||||
new vscode.CodeLens(line.range, {
|
||||
title: "Save",
|
||||
tooltip: "Run and view the test and save the reference output",
|
||||
command: "typst-test-helper.saveFromLens",
|
||||
arguments: [name, attrs],
|
||||
arguments: [name],
|
||||
}),
|
||||
new vscode.CodeLens(line.range, {
|
||||
title: "Terminal",
|
||||
@ -163,49 +159,40 @@ class TestHelper {
|
||||
}
|
||||
|
||||
// Triggered when clicking "View" in the lens.
|
||||
private viewFromLens(name: string, attrs: string[]) {
|
||||
if (
|
||||
this.opened?.name == name &&
|
||||
this.opened.attrs.join(" ") == attrs.join(" ")
|
||||
) {
|
||||
private viewFromLens(name: string) {
|
||||
if (this.opened?.name == name) {
|
||||
this.opened.panel.reveal();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.opened) {
|
||||
this.opened.name = name;
|
||||
this.opened.attrs = attrs;
|
||||
this.opened.panel.title = name;
|
||||
} else {
|
||||
const panel = vscode.window.createWebviewPanel(
|
||||
"typst-test-helper.preview",
|
||||
name,
|
||||
vscode.ViewColumn.Beside,
|
||||
{ enableFindWidget: true, enableScripts: true }
|
||||
{ enableFindWidget: true }
|
||||
);
|
||||
|
||||
panel.onDidDispose(() => (this.opened = undefined));
|
||||
panel.webview.onDidReceiveMessage((message) => {
|
||||
if (message.command === "openFile") {
|
||||
vscode.env.openExternal(vscode.Uri.parse(message.uri));
|
||||
}
|
||||
});
|
||||
|
||||
this.opened = { name, attrs, panel };
|
||||
this.opened = { name, panel };
|
||||
}
|
||||
|
||||
this.refreshWebView();
|
||||
}
|
||||
|
||||
// Triggered when clicking "Run" in the lens.
|
||||
private runFromLens(name: string, attrs: string[]) {
|
||||
this.viewFromLens(name, attrs);
|
||||
private runFromLens(name: string) {
|
||||
this.viewFromLens(name);
|
||||
this.runFromPreview();
|
||||
}
|
||||
|
||||
// Triggered when clicking "Run" in the lens.
|
||||
private saveFromLens(name: string, attrs: string[]) {
|
||||
this.viewFromLens(name, attrs);
|
||||
private saveFromLens(name: string) {
|
||||
this.viewFromLens(name);
|
||||
this.saveFromPreview();
|
||||
}
|
||||
|
||||
@ -301,37 +288,41 @@ class TestHelper {
|
||||
private copyImageFilePathFromPreviewContext(webviewSection: string) {
|
||||
if (!this.opened) return;
|
||||
const { name } = this.opened;
|
||||
const [bucket, format] = webviewSection.split("/");
|
||||
vscode.env.clipboard.writeText(
|
||||
getUri(name, bucket as Bucket, format as Format).fsPath
|
||||
);
|
||||
const { png, ref } = getImageUris(name);
|
||||
switch (webviewSection) {
|
||||
case "png":
|
||||
vscode.env.clipboard.writeText(png.fsPath);
|
||||
break;
|
||||
case "ref":
|
||||
vscode.env.clipboard.writeText(ref.fsPath);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Reloads the web view.
|
||||
private refreshWebView(output?: { stdout: string; stderr: string }) {
|
||||
if (!this.opened) return;
|
||||
|
||||
const { name, attrs, panel } = this.opened;
|
||||
const { name, panel } = this.opened;
|
||||
const { png, ref } = getImageUris(name);
|
||||
|
||||
if (panel) {
|
||||
console.log(
|
||||
`Refreshing WebView for ${name}` +
|
||||
(panel.visible ? " in background" : "")
|
||||
);
|
||||
|
||||
`Refreshing WebView for ${name}` + (panel.visible ? " in background" : ""));
|
||||
const webViewSrcs = {
|
||||
png: panel.webview.asWebviewUri(png),
|
||||
ref: panel.webview.asWebviewUri(ref),
|
||||
};
|
||||
panel.webview.html = "";
|
||||
|
||||
// Make refresh notable.
|
||||
setTimeout(async () => {
|
||||
setTimeout(() => {
|
||||
if (!panel) {
|
||||
throw new Error("panel to refresh is falsy after waiting");
|
||||
}
|
||||
panel.webview.html = await getWebviewContent(
|
||||
panel,
|
||||
name,
|
||||
attrs,
|
||||
output
|
||||
);
|
||||
panel.webview.html = getWebviewContent(webViewSrcs, output);
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
@ -395,43 +386,30 @@ function getWorkspaceRoot() {
|
||||
return vscode.workspace.workspaceFolders![0].uri;
|
||||
}
|
||||
|
||||
const EXTENSION = { html: "html", render: "png" };
|
||||
|
||||
type Bucket = "store" | "ref";
|
||||
type Format = "html" | "render";
|
||||
|
||||
function getUri(name: string, bucket: Bucket, format: Format) {
|
||||
let path;
|
||||
if (bucket === "ref" && format === "render") {
|
||||
path = `tests/ref/${name}.png`;
|
||||
} else {
|
||||
path = `tests/${bucket}/${format}/${name}.${EXTENSION[format]}`;
|
||||
}
|
||||
return vscode.Uri.joinPath(getWorkspaceRoot(), path);
|
||||
// Returns the URIs for a test's images.
|
||||
function getImageUris(name: string) {
|
||||
const root = getWorkspaceRoot();
|
||||
const png = vscode.Uri.joinPath(root, `tests/store/render/${name}.png`);
|
||||
const ref = vscode.Uri.joinPath(root, `tests/ref/${name}.png`);
|
||||
return { png, ref };
|
||||
}
|
||||
|
||||
// Produces the content of the WebView.
|
||||
async function getWebviewContent(
|
||||
panel: vscode.WebviewPanel,
|
||||
name: string,
|
||||
attrs: string[],
|
||||
function getWebviewContent(
|
||||
webViewSrcs: { png: vscode.Uri; ref: vscode.Uri },
|
||||
output?: {
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}
|
||||
): Promise<string> {
|
||||
const showHtml = attrs.includes("html");
|
||||
const showRender = !showHtml || attrs.includes("render");
|
||||
): string {
|
||||
const escape = (text: string) =>
|
||||
text.replace(/</g, "<").replace(/>/g, ">");
|
||||
|
||||
const stdout = output?.stdout
|
||||
? `<h2>Standard output</h2><pre class="output">${escape(
|
||||
output.stdout
|
||||
)}</pre>`
|
||||
const stdoutHtml = output?.stdout
|
||||
? `<h1>Standard output</h1><pre>${escape(output.stdout)}</pre>`
|
||||
: "";
|
||||
const stderr = output?.stderr
|
||||
? `<h2>Standard error</h2><pre class="output">${escape(
|
||||
output.stderr
|
||||
)}</pre>`
|
||||
const stderrHtml = output?.stderr
|
||||
? `<h1>Standard error</h1><pre>${escape(output.stderr)}</pre>`
|
||||
: "";
|
||||
|
||||
return `
|
||||
@ -471,169 +449,46 @@ async function getWebviewContent(
|
||||
color: #bebebe;
|
||||
content: "Not present";
|
||||
}
|
||||
h2 {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
h2 a {
|
||||
color: var(--vscode-editor-foreground);
|
||||
text-decoration: underline;
|
||||
}
|
||||
h2 a:hover {
|
||||
cursor: pointer;
|
||||
pre {
|
||||
display: inline-block;
|
||||
font-family: var(--vscode-editor-font-family);
|
||||
text-align: left;
|
||||
width: 80%;
|
||||
}
|
||||
.flex {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
.vertical {
|
||||
flex-direction: column;
|
||||
}
|
||||
.top-bottom {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-inline: 32px;
|
||||
width: calc(100vw - 64px);
|
||||
}
|
||||
pre {
|
||||
font-family: var(--vscode-editor-font-family);
|
||||
text-align: left;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
pre.output {
|
||||
display: inline-block;
|
||||
width: 80%;
|
||||
margin-block-start: 0;
|
||||
}
|
||||
pre.shiki {
|
||||
background-color: transparent !important;
|
||||
padding: 12px;
|
||||
margin-block-start: 0;
|
||||
}
|
||||
pre.shiki code {
|
||||
--vscode-textPreformat-background: transparent;
|
||||
}
|
||||
iframe, pre.shiki {
|
||||
border: 1px solid rgb(189, 191, 204);
|
||||
border-radius: 6px;
|
||||
}
|
||||
iframe {
|
||||
background: white;
|
||||
}
|
||||
.vscode-dark iframe {
|
||||
filter: invert(1) hue-rotate(180deg);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
const api = acquireVsCodeApi()
|
||||
function openFile(uri) {
|
||||
api.postMessage({ command: 'openFile', uri });
|
||||
}
|
||||
function sizeIframe(obj){
|
||||
obj.style.height = 0;
|
||||
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
${showRender ? renderSection(panel, name) : ""}
|
||||
${showHtml ? await htmlSection(name) : ""}
|
||||
${stdout}
|
||||
${stderr}
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
function renderSection(panel: vscode.WebviewPanel, name: string) {
|
||||
const outputUri = getUri(name, "store", "render");
|
||||
const refUri = getUri(name, "ref", "render");
|
||||
return `<div
|
||||
<div
|
||||
class="flex"
|
||||
data-vscode-context='{"preventDefaultContextMenuItems": true}'
|
||||
>
|
||||
<div>
|
||||
${linkedTitle("Output", outputUri)}
|
||||
<h1>Output</h1>
|
||||
<img
|
||||
class="output"
|
||||
data-vscode-context='{"bucket":"store", format: "render"}'
|
||||
src="${panel.webview.asWebviewUri(outputUri)}"
|
||||
data-vscode-context='{"webviewSection":"png"}'
|
||||
src="${webViewSrcs.png}"
|
||||
alt="Placeholder"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
${linkedTitle("Reference", refUri)}
|
||||
<h1>Reference</h1>
|
||||
<img
|
||||
class="ref"
|
||||
data-vscode-context='{"bucket":"ref", format: "render"}'
|
||||
src="${panel.webview.asWebviewUri(refUri)}"
|
||||
data-vscode-context='{"webviewSection":"ref"}'
|
||||
src="${webViewSrcs.ref}"
|
||||
alt="Placeholder"
|
||||
>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
async function htmlSection(name: string) {
|
||||
const storeHtml = await htmlSnippet(
|
||||
"HTML Output",
|
||||
getUri(name, "store", "html")
|
||||
);
|
||||
const refHtml = await htmlSnippet(
|
||||
"HTML Reference",
|
||||
getUri(name, "ref", "html")
|
||||
);
|
||||
return `<div
|
||||
class="flex vertical"
|
||||
data-vscode-context='{"preventDefaultContextMenuItems": true}'
|
||||
>
|
||||
${storeHtml}
|
||||
${refHtml}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
async function htmlSnippet(title: string, uri: vscode.Uri): Promise<string> {
|
||||
try {
|
||||
const data = await vscode.workspace.fs.readFile(uri);
|
||||
const code = new TextDecoder("utf-8").decode(data);
|
||||
return `<div>
|
||||
${linkedTitle(title, uri)}
|
||||
<div class="top-bottom">
|
||||
${await highlight(code)}
|
||||
<iframe srcdoc="${escape(code)}"></iframe>
|
||||
</div>
|
||||
</div>`;
|
||||
} catch {
|
||||
return `<div><h2>${title}</h2>Not present</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function linkedTitle(title: string, uri: vscode.Uri) {
|
||||
return `<h2><a onclick="openFile('${uri.toString()}')">${title}</a></h2>`;
|
||||
}
|
||||
|
||||
async function highlight(code: string): Promise<string> {
|
||||
return (await shiki).codeToHtml(code, {
|
||||
lang: "html",
|
||||
theme: selectTheme(),
|
||||
});
|
||||
}
|
||||
|
||||
function selectTheme() {
|
||||
switch (vscode.window.activeColorTheme.kind) {
|
||||
case vscode.ColorThemeKind.Light:
|
||||
case vscode.ColorThemeKind.HighContrastLight:
|
||||
return "github-light";
|
||||
case vscode.ColorThemeKind.Dark:
|
||||
case vscode.ColorThemeKind.HighContrast:
|
||||
return "github-dark";
|
||||
}
|
||||
}
|
||||
|
||||
function escape(text: string) {
|
||||
return text
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
${stdoutHtml}
|
||||
${stderrHtml}
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"lib": ["ES2022", "DOM"],
|
||||
"module": "Node16",
|
||||
"target": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"outDir": "dist",
|
||||
"lib": ["ES2022"],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true
|
||||
|
Loading…
x
Reference in New Issue
Block a user