rehype-katex
Advanced tools
Comparing version 6.0.2 to 6.0.3
@@ -1,9 +0,4 @@ | ||
/** | ||
* Plugin to transform `<span class=math-inline>` and `<div class=math-display>` | ||
* with KaTeX. | ||
* | ||
* @type {import('unified').Plugin<[Options?]|void[], Root>} | ||
*/ | ||
export default function rehypeKatex( | ||
options: void | katex.KatexOptions | undefined | ||
this: import('unified').Processor<void, import('hast').Root, void, void>, | ||
...settings: [(import('katex').KatexOptions | undefined)?] | void[] | ||
): | ||
@@ -14,2 +9,1 @@ | void | ||
export type Options = import('katex').KatexOptions | ||
import katex from 'katex' |
28
index.js
@@ -8,11 +8,7 @@ /** | ||
import {visit} from 'unist-util-visit' | ||
import {removePosition} from 'unist-util-remove-position' | ||
import {toText} from 'hast-util-to-text' | ||
import {unified} from 'unified' | ||
import rehypeParse from 'rehype-parse' | ||
import {fromHtmlIsomorphic} from 'hast-util-from-html-isomorphic' | ||
const assign = Object.assign | ||
const parseHtml = unified().use(rehypeParse, {fragment: true}) | ||
const source = 'rehype-katex' | ||
@@ -60,2 +56,21 @@ | ||
// KaTeX can handle `ParseError` itself, but not others. | ||
// Generate similar markup if this is an other error. | ||
// See: <https://github.com/KaTeX/KaTeX/blob/5dc7af0/docs/error.md>. | ||
if (error.name !== 'ParseError') { | ||
element.children = [ | ||
{ | ||
type: 'element', | ||
tagName: 'span', | ||
properties: { | ||
className: ['katex-error'], | ||
title: String(error), | ||
style: 'color:' + (settings.errorColor || '#cc0000') | ||
}, | ||
children: [{type: 'text', value}] | ||
} | ||
] | ||
return | ||
} | ||
result = katex.renderToString( | ||
@@ -71,6 +86,7 @@ value, | ||
const root = fromHtmlIsomorphic(result, {fragment: true}) | ||
// @ts-expect-error: assume no `doctypes` in KaTeX result. | ||
element.children = removePosition(parseHtml.parse(result), true).children | ||
element.children = root.children | ||
}) | ||
} | ||
} |
{ | ||
"name": "rehype-katex", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"description": "rehype plugin to transform inline and block math with KaTeX", | ||
@@ -42,8 +42,6 @@ "license": "MIT", | ||
"@types/hast": "^2.0.0", | ||
"@types/katex": "^0.11.0", | ||
"@types/katex": "^0.14.0", | ||
"hast-util-from-html-isomorphic": "^1.0.0", | ||
"hast-util-to-text": "^3.1.0", | ||
"katex": "^0.15.0", | ||
"rehype-parse": "^8.0.0", | ||
"unified": "^10.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"katex": "^0.16.0", | ||
"unist-util-visit": "^4.0.0" | ||
@@ -50,0 +48,0 @@ }, |
@@ -60,13 +60,13 @@ # rehype-katex | ||
In Deno with [Skypack][]: | ||
In Deno with [`esm.sh`][esmsh]: | ||
```js | ||
import rehypeKatex from 'https://cdn.skypack.dev/rehype-katex@6?dts' | ||
import rehypeKatex from 'https://esm.sh/rehype-katex@6' | ||
``` | ||
In browsers with [Skypack][]: | ||
In browsers with [`esm.sh`][esmsh]: | ||
```html | ||
<script type="module"> | ||
import rehypeKatex from 'https://cdn.skypack.dev/rehype-katex@6?min' | ||
import rehypeKatex from 'https://esm.sh/rehype-katex@6?bundle' | ||
</script> | ||
@@ -100,16 +100,12 @@ ``` | ||
main() | ||
const file = await unified() | ||
.use(rehypeParse, {fragment: true}) | ||
.use(rehypeKatex) | ||
.use(rehypeDocument, { | ||
css: 'https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css' | ||
}) | ||
.use(rehypeStringify) | ||
.process(await read('example.html')) | ||
async function main() { | ||
const file = await unified() | ||
.use(rehypeParse, {fragment: true}) | ||
.use(rehypeKatex) | ||
.use(rehypeDocument, { | ||
css: 'https://cdn.jsdelivr.net/npm/katex@0.15.0/dist/katex.min.css' | ||
}) | ||
.use(rehypeStringify) | ||
.process(await read('example.html')) | ||
console.log(String(file)) | ||
} | ||
console.log(String(file)) | ||
``` | ||
@@ -126,3 +122,3 @@ | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.0/dist/katex.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css"> | ||
</head> | ||
@@ -167,5 +163,7 @@ <body> | ||
```html | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.0/dist/katex.min.css" integrity="sha384-RZU/ijkSsFbcmivfdRBQDtwuwVqK7GMOw6IMvKyeWL2K5UAlyp6WonmB8m7Jd0Hn" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css" integrity="sha384-Xi8rHCmBmhbuyyhbI88391ZKP2dmfnOl4rT9ZfRI7mLTdk1wblIUnrIq35nqwEvC" crossorigin="anonymous"> | ||
``` | ||
<!-- To update the above, read the note in the monorepo readme. --> | ||
## Syntax tree | ||
@@ -203,3 +201,3 @@ | ||
```js | ||
import rehypeSanitize, {defaultSchema} from 'rehype-stringify' | ||
import rehypeSanitize, {defaultSchema} from 'rehype-sanitize' | ||
@@ -286,3 +284,3 @@ const mathSanitizeSchema = { | ||
[skypack]: https://www.skypack.dev | ||
[esmsh]: https://esm.sh | ||
@@ -289,0 +287,0 @@ [health]: https://github.com/remarkjs/.github |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13019
6
84
312
+ Added@types/katex@0.14.0(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedhast-util-from-dom@4.2.0(transitive)
+ Addedhast-util-from-html@1.0.2(transitive)
+ Addedhast-util-from-html-isomorphic@1.0.0(transitive)
+ Addedkatex@0.16.11(transitive)
+ Addedparse5@7.2.1(transitive)
- Removedrehype-parse@^8.0.0
- Removedunified@^10.0.0
- Removedunist-util-remove-position@^4.0.0
- Removed@types/katex@0.11.1(transitive)
- Removedbail@2.0.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedis-plain-obj@4.1.0(transitive)
- Removedkatex@0.15.6(transitive)
- Removedparse5@6.0.1(transitive)
- Removedrehype-parse@8.0.5(transitive)
- Removedtrough@2.2.0(transitive)
- Removedunified@10.1.2(transitive)
Updated@types/katex@^0.14.0
Updatedkatex@^0.16.0