mirror of
https://github.com/alrayyes/wiki.git
synced 2025-06-01 03:40:59 +00:00
fix: catch html to jsx errors (closes #547)
This commit is contained in:
parent
dc834015d0
commit
60b3bc34cb
7 changed files with 29 additions and 21 deletions
15
quartz/util/jsx.ts
Normal file
15
quartz/util/jsx.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
|
||||
import { QuartzPluginData } from "../plugins/vfile"
|
||||
import { Node, Root } from "hast"
|
||||
import { Fragment, jsx, jsxs } from "preact/jsx-runtime"
|
||||
import { trace } from "./trace"
|
||||
import { type FilePath } from "./path"
|
||||
|
||||
export function htmlToJsx(fp: FilePath, tree: Node<QuartzPluginData>) {
|
||||
try {
|
||||
// @ts-ignore (preact makes it angry)
|
||||
return toJsxRuntime(tree as Root, { Fragment, jsx, jsxs, elementAttributeNameCase: "html" })
|
||||
} catch (e) {
|
||||
trace(`Failed to parse Markdown in \`${fp}\` into JSX`, e as Error)
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import { isMainThread } from "workerpool"
|
|||
|
||||
const rootFile = /.*at file:/
|
||||
export function trace(msg: string, err: Error) {
|
||||
const stack = err.stack
|
||||
let stack = err.stack ?? ""
|
||||
|
||||
const lines: string[] = []
|
||||
|
||||
|
@ -12,15 +12,11 @@ export function trace(msg: string, err: Error) {
|
|||
lines.push(
|
||||
"\n" +
|
||||
chalk.bgRed.black.bold(" ERROR ") +
|
||||
"\n" +
|
||||
"\n\n" +
|
||||
chalk.red(` ${msg}`) +
|
||||
(err.message.length > 0 ? `: ${err.message}` : ""),
|
||||
)
|
||||
|
||||
if (!stack) {
|
||||
return
|
||||
}
|
||||
|
||||
let reachedEndOfLegibleTrace = false
|
||||
for (const line of stack.split("\n").slice(1)) {
|
||||
if (reachedEndOfLegibleTrace) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue