Skip to content

Commit

Permalink
Refactor to use @imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 19, 2024
1 parent 0c0a49d commit de17d3f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
9 changes: 3 additions & 6 deletions packages/rehype-katex/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Root} Root
*
* @typedef {import('katex').KatexOptions} KatexOptions
*
* @typedef {import('vfile').VFile} VFile
* @import {ElementContent, Root} from 'hast'
* @import {KatexOptions} from 'katex'
* @import {VFile} from 'vfile'
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/rehype-mathjax/lib/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('./create-plugin.js').InputTexOptions} InputTexOptions
* @import {InputTexOptions} from './create-plugin.js'
*/

import {createPlugin} from './create-plugin.js'
Expand Down
4 changes: 1 addition & 3 deletions packages/rehype-mathjax/lib/create-plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Root} Root
* @import {ElementContent, Element, Root} from 'hast'
*/

/**
Expand Down
13 changes: 6 additions & 7 deletions packages/rehype-mathjax/lib/create-renderer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mathjax-full/js/core/MathDocument.js').MathDocument<HTMLElement, Text, Document>} MathDocument
* @typedef {import('mathjax-full/js/core/OutputJax.js').OutputJax<HTMLElement, Text, Document>} OutputJax
* @typedef {import('./create-plugin.js').Options} Options
* @typedef {import('./create-plugin.js').Renderer} Renderer
* @import {Element} from 'hast'
* @import {MathDocument} from 'mathjax-full/js/core/MathDocument.js'
* @import {OutputJax} from 'mathjax-full/js/core/OutputJax.js'
* @import {Options, Renderer} from './create-plugin.js'
*/

import {fromDom} from 'hast-util-from-dom'
Expand Down Expand Up @@ -33,14 +32,14 @@ RegisterHTMLHandler(adapter)
*
* @param {Options} options
* Configuration.
* @param {OutputJax} output
* @param {OutputJax<HTMLElement, Text, Document>} output
* Output jax.
* @returns {Renderer}
* Rendeder.
*/
export function createRenderer(options, output) {
const input = new TeX({packages: AllPackages, ...options.tex})
/** @type {MathDocument} */
/** @type {MathDocument<HTMLElement, Text, Document>} */
const document = mathjax.document('', {InputJax: input, OutputJax: output})

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-math/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('mdast-util-math').ToOptions} Options
*/

export {default} from './lib/index.js'
14 changes: 6 additions & 8 deletions packages/remark-math/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// <reference types="mdast-util-math" />
/// <reference types="remark-parse" />
/// <reference types="remark-stringify" />

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast-util-math').ToOptions} Options
* @typedef {import('unified').Processor<Root>} Processor
* @import {ToOptions as Options} from 'mdast-util-math'
* @import {Root} from 'mdast'
* @import {} from 'remark-parse'
* @import {} from 'remark-stringify'
* @import {Processor} from 'unified'
*/

import {mathFromMarkdown, mathToMarkdown} from 'mdast-util-math'
Expand All @@ -25,7 +23,7 @@ const emptyOptions = {}
export default function remarkMath(options) {
// @ts-expect-error: TS is wrong about `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {Processor} */ (this)
const self = /** @type {Processor<Root>} */ (this)
const settings = options || emptyOptions
const data = self.data()

Expand Down
8 changes: 5 additions & 3 deletions packages/remark-math/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,16 @@ If you’re working with the syntax tree, you can register the new node types
with `@types/mdast` by adding a reference:

```js
// Register math nodes in mdast:
/// <reference types="mdast-util-math" />
/**
* @import {} from 'mdast-util-math' // Register math nodes.
* @import {Root} from 'mdast'
*/

import {visit} from 'unist-util-visit'

function myRemarkPlugin() {
/**
* @param {import('mdast').Root} tree
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
Expand Down

0 comments on commit de17d3f

Please sign in to comment.