-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
15 additions
and
182 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
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,172 +1,26 @@ | ||
# remark-html-katex | ||
|
||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
[![Sponsors][sponsors-badge]][collective] | ||
[![Backers][backers-badge]][collective] | ||
[![Chat][chat-badge]][chat] | ||
**Stability: Legacy**. | ||
This package is no longer recommended for use. | ||
It’s still covered by semantic-versioning guarantees and not yet deprecated, | ||
but use of this package should be avoided. | ||
Please use `remark-rehype` to move from remark (markdown) to rehype (HTML) | ||
and then replace `remark-html-katex` with [`rehype-katex`][rehype-katex] | ||
or [`rehype-mathjax`][rehype-mathjax]. | ||
|
||
[**remark**][remark] plugin to transform `inlineMath` and `math` nodes with | ||
[KaTeX][] for [`remark-html`][remark-html]. | ||
|
||
> This package integrates with [`remark-html`][remark-html]. | ||
> It’s better to work with [**rehype**][rehype], which is specifically made | ||
> for HTML, and to use [`rehype-katex`][rehype-katex] instead of this package. | ||
## Install | ||
|
||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
|
||
[npm][]: | ||
|
||
```sh | ||
npm install remark-html-katex | ||
``` | ||
|
||
## Use | ||
|
||
Say we have the following file, `example.md`: | ||
|
||
```markdown | ||
Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation. | ||
|
||
$$ | ||
L = \frac{1}{2} \rho v^2 S C_L | ||
$$ | ||
``` | ||
|
||
And our module, `example.js`, looks as follows: | ||
|
||
```js | ||
import {readSync} from 'to-vfile' | ||
import {unified} from 'unified' | ||
import remarkParse from 'remark-parse' | ||
import remarkMath from 'remark-math' | ||
import remarkHtmlKatex from 'remark-html-katex' | ||
import remarkHtml from 'remark-html' | ||
|
||
const file = readSync('example.md') | ||
|
||
unified() | ||
.use(remarkParse) | ||
.use(remarkMath) | ||
.use(remarkHtmlKatex) | ||
.use(remarkHtml) | ||
.process(file) | ||
.then((file) => { | ||
console.log(String(file)) | ||
}) | ||
``` | ||
|
||
Now, running `node example` yields: | ||
|
||
```html | ||
<p>Lift(<span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>L</mi></mrow><annotation encoding="application/x-tex">L</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">L</span></span></span></span></span>) can be determined by Lift Coefficient (<span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>C</mi><mi>L</mi></msub></mrow><annotation encoding="application/x-tex">C_L</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.07153em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">L</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>) like the following equation.</p> | ||
<div class="math math-display"><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>L</mi><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mi>ρ</mi><msup><mi>v</mi><mn>2</mn></msup><mi>S</mi><msub><mi>C</mi><mi>L</mi></msub></mrow><annotation encoding="application/x-tex">L = \frac{1}{2} \rho v^2 S C_L</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">L</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.00744em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">2</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord mathnormal">ρ</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.32833099999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.07153em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">L</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span></div> | ||
``` | ||
|
||
## API | ||
|
||
This package exports no identifiers. | ||
The default export is `remarkHtmlKatex`. | ||
|
||
### `unified().use(remarkHtmlKatex[, options])` | ||
|
||
Transform `inlineMath` and `math` nodes with [KaTeX][] for | ||
[`remark-html`][remark-html]. | ||
|
||
#### `options` | ||
|
||
##### `options.throwOnError` | ||
|
||
Throw if a KaTeX parse error occurs (`boolean`, default: `false`). | ||
See [KaTeX options][katex-options]. | ||
|
||
##### `options.<*>` | ||
|
||
All other options, except for `displayMode`, are passed to | ||
[KaTeX][katex-options]. | ||
|
||
## Security | ||
|
||
Use of `remark-html-katex` renders user content with [KaTeX][], so any | ||
vulnerability in KaTeX can open you to a [cross-site scripting (XSS)][xss] | ||
attack. | ||
|
||
Always be wary of user input and use the [`sanitize`][remark-html-sanitize] | ||
option of `remark-html`. | ||
|
||
## Contribute | ||
|
||
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways | ||
to get started. | ||
See [`support.md`][support] for ways to get help. | ||
|
||
This project has a [code of conduct][coc]. | ||
By interacting with this repository, organization, or community you agree to | ||
abide by its terms. | ||
Legacy [documentation for this package](https://github.com/remarkjs/remark-math/tree/52b145855df58e0cd85c2171452f192181cfb43d/packages/remark-html-katex) | ||
is still available in Git. | ||
|
||
## License | ||
|
||
[MIT][license] © [Junyoung Choi][author] | ||
|
||
<!-- Definitions --> | ||
|
||
[build-badge]: https://github.com/remarkjs/remark-math/workflows/main/badge.svg | ||
|
||
[build]: https://github.com/remarkjs/remark-math/actions | ||
|
||
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-math.svg | ||
|
||
[coverage]: https://codecov.io/github/remarkjs/remark-math | ||
|
||
[downloads-badge]: https://img.shields.io/npm/dm/remark-html-katex.svg | ||
|
||
[downloads]: https://www.npmjs.com/package/remark-html-katex | ||
|
||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-html-katex.svg | ||
|
||
[size]: https://bundlephobia.com/result?p=remark-html-katex | ||
|
||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
|
||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg | ||
|
||
[collective]: https://opencollective.com/unified | ||
|
||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
|
||
[chat]: https://github.com/remarkjs/remark/discussions | ||
|
||
[npm]: https://docs.npmjs.com/cli/install | ||
|
||
[health]: https://github.com/remarkjs/.github | ||
|
||
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md | ||
|
||
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md | ||
|
||
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md | ||
|
||
[license]: https://github.com/remarkjs/remark-math/blob/main/license | ||
|
||
[author]: https://rokt33r.github.io | ||
|
||
[remark]: https://github.com/remarkjs/remark | ||
|
||
[remark-html]: https://github.com/remarkjs/remark-html | ||
|
||
[remark-html-sanitize]: https://github.com/remarkjs/remark-html#optionssanitize | ||
|
||
[rehype]: https://github.com/rehypejs/rehype | ||
|
||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
|
||
[katex]: https://github.com/Khan/KaTeX | ||
|
||
[katex-options]: https://katex.org/docs/options.html | ||
|
||
[rehype-katex]: https://github.com/remarkjs/remark-math/tree/main/packages/rehype-katex | ||
|
||
[rehype-mathjax]: https://github.com/remarkjs/remark-math/tree/main/packages/rehype-mathjax |
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