diff --git a/dev/index.d.ts b/dev/index.d.ts index 3e52f68..d09f0e5 100644 --- a/dev/index.d.ts +++ b/dev/index.d.ts @@ -1,7 +1,52 @@ -export {mathHtml, type Options as HtmlOptions} from './lib/html.js' -export {math, type Options} from './lib/syntax.js' +import type {KatexOptions} from 'katex' +export {mathHtml} from './lib/html.js' +export {math} from './lib/syntax.js' + +/** + * Configuration for HTML output. + * + * > 👉 **Note**: passed to `katex.renderToString`. + * > `displayMode` is overwritten by this plugin, to `false` for math in + * > text (inline), and `true` for math in flow (block). + */ +export interface HtmlOptions extends KatexOptions { + /** + * The field `displayMode` cannot be passed to `micromark-extension-math`. + * It is overwritten by it, + * to `false` for math in text (inline) and `true` for math in flow (block). + */ + displayMode?: never +} + +/** + * Configuration. + */ +export interface Options { + /** + * Whether to support math (text) with a single dollar (default: `true`). + * + * Single dollars work in Pandoc and many other places, but often interfere + * with “normal” dollars in text. + * If you turn this off, you can use two or more dollars for text math. + */ + singleDollarTextMath?: boolean | null | undefined +} + +/** + * Augment types. + */ declare module 'micromark-util-types' { + /** + * Compile data. + */ + interface CompileData { + mathFlowOpen?: boolean + } + + /** + * Token types. + */ interface TokenTypeMap { mathFlow: 'mathFlow' mathFlowFence: 'mathFlowFence' @@ -13,8 +58,4 @@ declare module 'micromark-util-types' { mathTextPadding: 'mathTextPadding' mathTextSequence: 'mathTextSequence' } - - interface CompileData { - mathFlowOpen?: boolean - } } diff --git a/dev/lib/html.js b/dev/lib/html.js index fd525c3..635d8df 100644 --- a/dev/lib/html.js +++ b/dev/lib/html.js @@ -1,15 +1,6 @@ /** - * @typedef {import('katex').KatexOptions} KatexOptions - * @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension - */ - -/** - * @typedef {Omit} Options - * Configuration for HTML output. - * - * > 👉 **Note**: passed to `katex.renderToString`. - * > `displayMode` is overwritten by this plugin, to `false` for math in - * > text (inline), and `true` for math in flow (block). + * @import {HtmlOptions as Options} from 'micromark-extension-math' + * @import {HtmlExtension} from 'micromark-util-types' */ import katex from 'katex' diff --git a/dev/lib/math-flow.js b/dev/lib/math-flow.js index 884fb8d..8f0d6a0 100644 --- a/dev/lib/math-flow.js +++ b/dev/lib/math-flow.js @@ -1,8 +1,5 @@ /** - * @typedef {import('micromark-util-types').Construct} Construct - * @typedef {import('micromark-util-types').State} State - * @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext - * @typedef {import('micromark-util-types').Tokenizer} Tokenizer + * @import {Construct, State, TokenizeContext, Tokenizer} from 'micromark-util-types' */ import {ok as assert} from 'devlop' diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js index b1dece5..89bc08b 100644 --- a/dev/lib/math-text.js +++ b/dev/lib/math-text.js @@ -1,21 +1,6 @@ /** - * @typedef {import('micromark-util-types').Construct} Construct - * @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext - * @typedef {import('micromark-util-types').Tokenizer} Tokenizer - * @typedef {import('micromark-util-types').Previous} Previous - * @typedef {import('micromark-util-types').Resolver} Resolver - * @typedef {import('micromark-util-types').State} State - * @typedef {import('micromark-util-types').Token} Token - * - * @typedef Options - * Configuration. - * @property {boolean | null | undefined} [singleDollarTextMath=true] - * Whether to support math (text) with a single dollar (default: `true`). - * - * Single dollars work in Pandoc and many other places, but often interfere - * with “normal” dollars in text. - * If you turn this off, you can use two or more dollars for text math. - + * @import {Options} from 'micromark-extension-math' + * @import {Construct, Previous, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' */ // To do: next major: clean spaces in HTML compiler. diff --git a/dev/lib/syntax.js b/dev/lib/syntax.js index 4253f03..501ad98 100644 --- a/dev/lib/syntax.js +++ b/dev/lib/syntax.js @@ -1,6 +1,6 @@ /** - * @typedef {import('micromark-util-types').Extension} Extension - * @typedef {import('./math-text.js').Options} Options + * @import {Options} from 'micromark-extension-math' + * @import {Extension} from 'micromark-util-types' */ import {codes} from 'micromark-util-symbol' diff --git a/package.json b/package.json index 646cb7a..97d19f1 100644 --- a/package.json +++ b/package.json @@ -89,10 +89,25 @@ "overrides": [ { "files": [ - "**/*.ts" + "**/*.d.ts" ], "rules": { - "@typescript-eslint/consistent-type-definitions": "off" + "@typescript-eslint/array-type": [ + "error", + { + "default": "generic" + } + ], + "@typescript-eslint/ban-types": [ + "error", + { + "extendDefaults": true + } + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "interface" + ] } } ],