Skip to content
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

feat: add convergent test in webapp #11

Merged
merged 2 commits into from
Mar 15, 2024
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
13 changes: 9 additions & 4 deletions web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ const { div, textarea, input, label, p, a } = van.tags;
const App = () => {
const input_val = van.state("")
const output = van.state("")
const error_message = van.state("")
const columns = van.state(80)
van.derive(
() => {
try {
output.val = pretty_print_wasm(input_val.val, columns.val)
} catch (e) {
output.val = e as string
error_message.val = ""
if (pretty_print_wasm(output.val, columns.val) !== output.val) {
throw new Error("Format doesn't converge! This means formatting the output again will result in a different output. This is a bug in the formatter. Please report it to https://github.com/Enter-tainer/typst-geshihua with the input code.")
}
} catch (e: any) {
error_message.val = e.message
}
}
)
return div(
p("Powered by ", a({
p("Online Typst Code Formatter. Powered by ", a({
href: "https://github.com/Enter-tainer/typst-geshihua"
}, "Typst Geshihua")),
textarea({
Expand Down Expand Up @@ -47,7 +52,7 @@ const App = () => {
columns.val = parseInt((event.target! as HTMLInputElement).value)
}
})
)
), div(p({ class: "error-message" }, error_message.val))
)
}

Expand Down
6 changes: 6 additions & 0 deletions web/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ textarea {
transition: border-color 0.25s;
width: 40%;
}

.error-message {
color: #ff4d4f;
margin-top: 0.5em;
font-family: monospace;
}
Loading