加入 TeX 渲染器
小於 1 分鐘...
本教學將指引你設定自己的 TeX 渲染器。
@waline/client 提供了 texRenderer 函式。客戶端會傳入是否為顯示模式以及原始
一個使用 KaTeX 的案例
關於 KaTeX 選項,請參閱 KaTeX API。
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Waline highlighter 案例</title>
<link rel="stylesheet" href="https://unpkg.com/@waline/client@v3/dist/waline.css" />
<link rel="stylesheet" href="https://unpkg.com/katex@v0.16/dist/katex.min.css" />
</head>
<body>
<div id="waline" style="max-width: 800px; margin: 0 auto"></div>
<script type="module">
import { init } from '"https://unpkg.com/@waline/client@v3/dist/waline.js"';
import katex from 'https://unpkg.com/katex@0.16/dist/katex.mjs';
init({
el: '#waline',
serverURL: 'https://waline.vercel.app',
path: '/',
lang: 'en-US',
texRenderer: (blockMode, tex) =>
katex.renderToString(tex, {
displayMode: blockMode,
throwOnError: false,
}),
});
</script>
</body>
</html>一個使用 MathJax 的案例
關於 MathJax 選項,請參閱 MathJax API。
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Waline highlighter 案例</title>
<link rel="stylesheet" href="https://unpkg.com/@waline/client@v3/dist/waline.css" />
<script src="https://unpkg.com/mathjax@v3/es5/tex-svg.js"></script>
</head>
<body>
<div id="waline" style="max-width: 800px; margin: 0 auto"></div>
<script type="module">
import { init } from '"https://unpkg.com/@waline/client@v3/dist/waline.js"';
init({
el: '#waline',
serverURL: 'https://waline.vercel.app',
path: '/',
lang: 'en-US',
texRenderer: (blockMode, tex) =>
window.MathJax.startup.adaptor.outerHTML(
window.MathJax.tex2svg(tex, {
display: blockMode,
}),
),
});
</script>
</body>
</html>TIPS: 評論區僅作評論展示,如有問題諮詢請去 Github Discussion 中提問。
