-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pnpm add -D katex remark-math for equation support in docs
- Loading branch information
Showing
8 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,13 @@ | |
|
||
<link rel="icon" href="/favicon.svg" /> | ||
<link rel="stylesheet" href="/prism-vsc-dark-plus.css" /> | ||
<!-- interactive plots --> | ||
<script src="https://cdn.plot.ly/plotly-2.14.0.min.js"></script> | ||
<!-- math display --> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" | ||
/> | ||
|
||
%sveltekit.head% | ||
</head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import adapter from '@sveltejs/adapter-static' | ||
import { fromString } from 'hast-util-from-string' | ||
import { selectAll } from 'hast-util-select' | ||
import { toString } from 'hast-util-to-string' | ||
import { s } from 'hastscript' | ||
import katex from 'katex' | ||
import { mdsvex } from 'mdsvex' | ||
import linkHeadings from 'rehype-autolink-headings' | ||
import headingSlugs from 'rehype-slug' | ||
import link_headings from 'rehype-autolink-headings' | ||
import heading_slugs from 'rehype-slug' | ||
import math from 'remark-math' | ||
import preprocess from 'svelte-preprocess' | ||
|
||
const rehypePlugins = [ | ||
headingSlugs, | ||
// from https://github.com/kwshi/rehype-katex-svelte | ||
(options = {}) => | ||
(tree) => { | ||
for (const node of selectAll(`.math-inline,.math-display`, tree)) { | ||
const displayMode = node.properties?.className?.includes(`math-display`) | ||
const rendered = katex.renderToString(toString(node), { | ||
...options, | ||
displayMode, | ||
}) | ||
fromString(node, `{@html ${JSON.stringify(rendered)}}`) | ||
} | ||
}, | ||
heading_slugs, | ||
[ | ||
linkHeadings, | ||
link_headings, | ||
{ | ||
behavior: `append`, | ||
test: [`h2`, `h3`, `h4`, `h5`, `h6`], // don't auto-link <h1> | ||
|
@@ -30,6 +47,9 @@ export default { | |
preprocess(), | ||
mdsvex({ | ||
rehypePlugins, | ||
// [email protected] pinned due to mdsvex, see | ||
// https://github.com/kwshi/rehype-katex-svelte#usage | ||
remarkPlugins: [math], | ||
extensions: [`.svx`, `.md`], | ||
}), | ||
], | ||
|