Я нуб на TS и JS.
Я хочу сделать плагин для ubsidian Quartz. Это производитель страниц, который превращает MD в HTML и запускает сервер. В моем случае я хочу, чтобы Tikz -коды в SVG Graphic. Поэтому я попытался сделать некоторые коды точно так же, как ниже. < /P>
import { QuartzTransformerPlugin } from "../types"
import { visit } from "unist-util-visit"
import { Root, Code } from "mdast"
import tex2svg from "node-tikzjax"
interface Options {
enableTikZJax: boolean
}
export const TikZJax: QuartzTransformerPlugin = (opts) => {
const enableTikZJax = opts?.enableTikZJax ?? true
return {
name: "TikZJax",
markdownPlugins() {
return [
() => {
return async (tree: Root) => {
if (!enableTikZJax) return
const promises: Promise[] = []
visit(tree, "code", (node: Code, index, parent) => {
if (node.lang === "tikz" && parent && typeof index === 'number') {
const tex = `${node.value}`
const promise = tex2svg(tex)
.then((svg: string) => {
parent.children[index] = {
type: "html",
value: svg
}
})
.catch((error: Error) => {
console.error('TikZ conversion failed:', error)
})
promises.push(promise)
}
})
await Promise.all(promises)
}
}
]
}
}
}
< /code>
Тем не менее, я застрял в ошибке, которая является «tex2svg не является функцией».
Я загрузил все зависимости для узла-тикжакса. И ниже приведен файл MD для транскрипта в HTML с файлом SVG.\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colormap/viridis]
\addplot3[
surf,
samples=18,
domain=-3:3
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{document}
< /code>
Установить все зависимости и переустановить < /li>
Попробуйте изменить форму импорта. < /li>
< /ol>
Подробнее здесь: https://stackoverflow.com/questions/797 ... a-function