Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-katex

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-katex - npm Package Compare versions

Comparing version 6.0.2 to 6.0.3

10

index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc