Refactor code-style
This commit is contained in:
parent
6e6c0ed89f
commit
d2b583b5ba
1 changed files with 23 additions and 22 deletions
45
index.js
45
index.js
|
@ -1,37 +1,38 @@
|
||||||
/**
|
/**
|
||||||
* @typedef {import('mdast').Root} Root
|
* @typedef {import('mdast').Root} Root
|
||||||
*
|
|
||||||
* @typedef {import('mdast-util-directive')} DoNotTouchAsThisImportIncludesDirectivesInTree
|
* @typedef {import('mdast-util-directive')} DoNotTouchAsThisImportIncludesDirectivesInTree
|
||||||
|
* @typedef {import('unified').Processor<Root>} Processor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {directive} from 'micromark-extension-directive'
|
import {directive} from 'micromark-extension-directive'
|
||||||
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin to support the generic directives proposal (`:cite[smith04]`,
|
* Add support for generic directives.
|
||||||
* `::youtube[Video of a cat in a box]{v=01ab2cd3efg}`, and such).
|
|
||||||
*
|
*
|
||||||
* @this {import('unified').Processor}
|
* @returns {undefined}
|
||||||
* @type {import('unified').Plugin<void[], Root>}
|
* Nothing.
|
||||||
*/
|
*/
|
||||||
export default function remarkDirective() {
|
export default function remarkDirective() {
|
||||||
const data = this.data()
|
// @ts-expect-error: TS is wrong about `this`.
|
||||||
|
// eslint-disable-next-line unicorn/no-this-assignment
|
||||||
|
const self = /** @type {Processor} */ (this)
|
||||||
|
const data = self.data()
|
||||||
|
|
||||||
add('micromarkExtensions', directive())
|
/** @type {Array<unknown>} */
|
||||||
add('fromMarkdownExtensions', directiveFromMarkdown)
|
// @ts-expect-error: to do: remove.
|
||||||
add('toMarkdownExtensions', directiveToMarkdown)
|
const micromarkExtensions =
|
||||||
|
data.micromarkExtensions || (data.micromarkExtensions = [])
|
||||||
|
/** @type {Array<unknown>} */
|
||||||
|
// @ts-expect-error: to do: remove.
|
||||||
|
const fromMarkdownExtensions =
|
||||||
|
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
|
||||||
|
/** @type {Array<unknown>} */
|
||||||
|
// @ts-expect-error: to do: remove.
|
||||||
|
const toMarkdownExtensions =
|
||||||
|
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])
|
||||||
|
|
||||||
/**
|
micromarkExtensions.push(directive())
|
||||||
* @param {string} field
|
fromMarkdownExtensions.push(directiveFromMarkdown)
|
||||||
* @param {unknown} value
|
toMarkdownExtensions.push(directiveToMarkdown)
|
||||||
*/
|
|
||||||
function add(field, value) {
|
|
||||||
const list = /** @type {unknown[]} */ (
|
|
||||||
// Other extensions
|
|
||||||
/* c8 ignore next 2 */
|
|
||||||
data[field] || (data[field] = [])
|
|
||||||
)
|
|
||||||
|
|
||||||
list.push(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue