diff --git a/package.json b/package.json index 168ef95..b337678 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ ], "type": "module", "workspaces": [ - "packages/remark-html-katex/", "packages/rehype-katex/", "packages/remark-math/", "packages/rehype-mathjax/" diff --git a/packages/remark-html-katex/.npmrc b/packages/remark-html-katex/.npmrc deleted file mode 100644 index 3757b30..0000000 --- a/packages/remark-html-katex/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -ignore-scripts=true -package-lock=false diff --git a/packages/remark-html-katex/index.js b/packages/remark-html-katex/index.js deleted file mode 100644 index d17ccbd..0000000 --- a/packages/remark-html-katex/index.js +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @typedef {import('mdast').Root} Root - * @typedef {import('katex').KatexOptions} Options - */ - -import {visit} from 'unist-util-visit' -import {removePosition} from 'unist-util-remove-position' -import katex from 'katex' -import {unified} from 'unified' -import rehypeParse from 'rehype-parse' - -const parseHtml = unified().use(rehypeParse, {fragment: true}) - -const source = 'remark-html-katex' - -/** - * Plugin to transform `inlineMath` and `math` nodes with KaTeX for - * `remark-html`. - * - * @type {import('unified').Plugin<[Options?]|void[], Root>} - */ -export default function remarkHtmlKatex(options = {}) { - const throwOnError = options.throwOnError || false - - return (tree, file) => { - visit(tree, (node) => { - if (node.type === 'inlineMath' || node.type === 'math') { - const displayMode = node.type === 'math' - /** @type {string} */ - let result - - try { - result = katex.renderToString( - node.value, - Object.assign({}, options, { - displayMode, - throwOnError: true - }) - ) - } catch (error_) { - const error = /** @type {Error} */ (error_) - const fn = throwOnError ? 'fail' : 'message' - const origin = [source, error.name.toLowerCase()].join(':') - - file[fn](error.message, node.position, origin) - - result = katex.renderToString( - node.value, - Object.assign({}, options, { - displayMode, - throwOnError: false, - strict: 'ignore' - }) - ) - } - - const tree = parseHtml.parse(result) - removePosition(tree) - - if (node.type === 'inlineMath') { - const data = node.data || (node.data = {}) - // @ts-expect-error: fine. - data.hChildren = tree.children - } else { - // @ts-expect-error: fine. - const scope = node.data.hChildren[0] - scope.children = tree.children - } - } - }) - } -} diff --git a/packages/remark-html-katex/package.json b/packages/remark-html-katex/package.json deleted file mode 100644 index f5929f8..0000000 --- a/packages/remark-html-katex/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "remark-html-katex", - "version": "4.0.1", - "description": "Legacy remark plugin to transform math with KaTeX — please use `rehype-katex` instead", - "license": "MIT", - "keywords": [], - "repository": "https://github.com/remarkjs/remark-math/tree/main/packages/remark-html-katex", - "bugs": "https://github.com/remarkjs/remark-math/issues", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - }, - "author": "Junyoung Choi (https://rokt33r.github.io)", - "contributors": [ - "Junyoung Choi (https://rokt33r.github.io)", - "Titus Wormer (https://wooorm.com)" - ], - "sideEffects": false, - "type": "module", - "main": "index.js", - "types": "index.d.ts", - "files": [ - "index.d.ts", - "index.js" - ], - "dependencies": { - "@types/katex": "^0.16.0", - "@types/mdast": "^4.0.0", - "katex": "^0.16.0", - "rehype-parse": "^9.0.0", - "unified": "^11.0.0", - "unist-util-remove-position": "^5.0.0", - "unist-util-visit": "^5.0.0" - }, - "scripts": { - "test-api": "node --conditions development test.js", - "test": "npm run build && npm run test-api" - }, - "xo": { - "prettier": true - } -} diff --git a/packages/remark-html-katex/readme.md b/packages/remark-html-katex/readme.md index a2d4524..15682a6 100644 --- a/packages/remark-html-katex/readme.md +++ b/packages/remark-html-katex/readme.md @@ -1,26 +1,8 @@ # remark-html-katex -**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]. +Deprecated. -Legacy [documentation for this package](https://github.com/remarkjs/remark-math/tree/52b145855df58e0cd85c2171452f192181cfb43d/packages/remark-html-katex) -is still available in Git. +[Git][] is still intact and previous versions can still be used without +warnings. -## License - -[MIT][license] © [Junyoung Choi][author] - - - -[license]: https://github.com/remarkjs/remark-math/blob/main/license - -[author]: https://rokt33r.github.io - -[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 +[git]: https://github.com/remarkjs/remark-math/tree/6d9970e/packages/remark-html-katex diff --git a/packages/remark-html-katex/test.js b/packages/remark-html-katex/test.js deleted file mode 100644 index 1f07b4a..0000000 --- a/packages/remark-html-katex/test.js +++ /dev/null @@ -1,174 +0,0 @@ -import assert from 'node:assert/strict' -import test from 'node:test' -import katex from 'katex' -import {unified} from 'unified' -import remarkParse from 'remark-parse' -import rehypeParse from 'rehype-parse' -import rehypeStringify from 'rehype-stringify' -import remarkHtml from 'remark-html' -import remarkMath from '../remark-math/index.js' -import remarkHtmlKatex from './index.js' - -test('remark-html-katex', async function (t) { - await t.test('should transform math with katex', async function () { - assert.deepEqual( - unified() - .use(remarkParse) - .use(remarkMath) - .use(remarkHtmlKatex) - // @ts-expect-error: to do: remove when `remark-html` is released. - .use(remarkHtml, {sanitize: false}) - .processSync( - [ - 'Inline math $\\alpha$.', - '', - 'Block math:', - '', - '$$', - '\\gamma', - '$$' - ].join('\n') - ) - .toString(), - unified() - .use(rehypeParse, {fragment: true}) - .use(rehypeStringify) - .processSync( - [ - '

Inline math ' + - katex.renderToString('\\alpha') + - '.

', - '

Block math:

', - '
' +
-              katex.renderToString('\\gamma', {displayMode: true}) +
-              '
', - '' - ].join('\n') - ) - .toString() - ) - }) - - await t.test('should support `macros`', async function () { - const macros = {'\\RR': '\\mathbb{R}'} - - assert.deepEqual( - unified() - .use(remarkParse) - .use(remarkMath) - .use(remarkHtmlKatex, {macros}) - // @ts-expect-error: to do: remove when `remark-html` is released. - .use(remarkHtml, {sanitize: false}) - .processSync('$\\RR$') - .toString(), - unified() - .use(rehypeParse, {fragment: true}) - .use(rehypeStringify) - .processSync( - '

' + - katex.renderToString('\\RR', {macros}) + - '

\n' - ) - .toString() - ) - }) - - await t.test('should support `errorColor`', async function () { - assert.deepEqual( - unified() - .use(remarkParse) - .use(remarkMath) - .use(remarkHtmlKatex, {errorColor: 'orange'}) - // @ts-expect-error: to do: remove when `remark-html` is released. - .use(remarkHtml, {sanitize: false}) - .processSync('$\\alpa$') - .toString(), - unified() - .use(rehypeParse, {fragment: true}) - .use(rehypeStringify) - .processSync( - '

' + - katex.renderToString('\\alpa', { - throwOnError: false, - errorColor: 'orange' - }) + - '

\n' - ) - .toString() - ) - }) - - await t.test('should create a message for errors', async function () { - assert.deepEqual( - unified() - .use(remarkParse) - .use(remarkMath) - .use(remarkHtmlKatex) - // @ts-expect-error: to do: remove when `remark-html` is released. - .use(remarkHtml, {sanitize: false}) - .processSync('Lorem\n$\\alpa$') - .messages.map(String), - [ - '2:1-2:8: KaTeX parse error: Undefined control sequence: \\alpa at position 1: \\̲a̲l̲p̲a̲' - ] - ) - }) - - await t.test( - 'should throw an error if `throwOnError: true`', - async function () { - try { - unified() - .use(remarkParse) - .use(remarkMath) - .use(remarkHtmlKatex, {throwOnError: true}) - // @ts-expect-error: to do: remove when `remark-html` is released. - .use(remarkHtml, {sanitize: false}) - .processSync('Lorem\n$\\alpa$') - } catch (error_) { - const error = /** @type {Error} */ (error_) - assert.equal( - error.message, - 'KaTeX parse error: Undefined control sequence: \\alpa at position 1: \\̲a̲l̲p̲a̲' - ) - } - } - ) - - await t.test('should support `strict: ignore`', async function () { - assert.deepEqual( - unified() - .use(remarkParse) - .use(remarkMath) - .use(remarkHtmlKatex, {errorColor: 'orange', strict: 'ignore'}) - // @ts-expect-error: to do: remove when `remark-html` is released. - .use(remarkHtml, {sanitize: false}) - .processSync('$ê&$') - .toString(), - unified() - .use(rehypeParse, {fragment: true}) - .use(rehypeStringify) - .processSync( - '

ê&

\n' - ) - .toString() - ) - }) - - await t.test('should support generated nodes', async function () { - const pipeline = unified() - .use(remarkHtmlKatex, {errorColor: 'orange', strict: 'ignore'}) - // @ts-expect-error: to do: remove when `remark-html` is released. - .use(remarkHtml, {sanitize: false}) - - assert.deepEqual( - pipeline.stringify( - pipeline.runSync({ - type: 'root', - children: [{type: 'inlineMath', value: '\\alpha'}] - }) - ), - '
' + katex.renderToString('\\alpha') + '
\n' - ) - }) -}) diff --git a/packages/remark-html-katex/tsconfig.json b/packages/remark-html-katex/tsconfig.json deleted file mode 100644 index 4082f16..0000000 --- a/packages/remark-html-katex/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.json" -}