mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-05 05:49:31 +08:00
31 lines
1,015 B
Text
31 lines
1,015 B
Text
/**
|
|
* @typedef {import('mdast').Root|import('mdast').Content} Node
|
|
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownOptions
|
|
* @typedef {Omit<ToMarkdownOptions, 'extensions'>} Options
|
|
*/
|
|
|
|
import {toMarkdown} from 'mdast-util-to-markdown'
|
|
|
|
/** @type {import('unified').Plugin<[Options]|void[], Node, string>} */
|
|
export default function remarkStringify(options) {
|
|
/** @type {import('unified').CompilerFunction<Node, string>} */
|
|
const compiler = (tree) => {
|
|
// Assume options.
|
|
const settings = /** @type {Options} */ (this.data('settings'))
|
|
|
|
return toMarkdown(
|
|
tree,
|
|
Object.assign({}, settings, options, {
|
|
// Note: this option is not in the readme.
|
|
// The goal is for it to be set by plugins on `data` instead of being
|
|
// passed by users.
|
|
extensions:
|
|
/** @type {ToMarkdownOptions['extensions']} */ (
|
|
this.data('toMarkdownExtensions')
|
|
) || []
|
|
})
|
|
)
|
|
}
|
|
|
|
Object.assign(this, {Compiler: compiler})
|
|
}
|