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 Jul 5, 2024
1 parent 7698074 commit a271caa
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 42 deletions.
53 changes: 47 additions & 6 deletions dev/index.d.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -13,8 +58,4 @@ declare module 'micromark-util-types' {
mathTextPadding: 'mathTextPadding'
mathTextSequence: 'mathTextSequence'
}

interface CompileData {
mathFlowOpen?: boolean
}
}
13 changes: 2 additions & 11 deletions dev/lib/html.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/**
* @typedef {import('katex').KatexOptions} KatexOptions
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/

/**
* @typedef {Omit<KatexOptions, 'displayMode'>} 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'
Expand Down
5 changes: 1 addition & 4 deletions dev/lib/math-flow.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
19 changes: 2 additions & 17 deletions dev/lib/math-text.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions dev/lib/syntax.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
],
Expand Down

0 comments on commit a271caa

Please sign in to comment.