Refactor to move code to lib/
This commit is contained in:
parent
a952370494
commit
9e219a3603
3 changed files with 41 additions and 39 deletions
40
index.js
40
index.js
|
@ -1,39 +1 @@
|
||||||
/// <reference types="remark-parse" />
|
export {default} from './lib/index.js'
|
||||||
/// <reference types="remark-stringify" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {import('mdast').Root} Root
|
|
||||||
* @typedef {import('mdast-util-directive')} DoNotTouchAsThisImportIncludesDirectivesInTree
|
|
||||||
* @typedef {import('unified').Processor<Root>} Processor
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
|
||||||
import {directive} from 'micromark-extension-directive'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add support for generic directives.
|
|
||||||
*
|
|
||||||
* ###### Notes
|
|
||||||
*
|
|
||||||
* Doesn’t handle the directives: create your own plugin to do that.
|
|
||||||
*
|
|
||||||
* @returns {undefined}
|
|
||||||
* Nothing.
|
|
||||||
*/
|
|
||||||
export default function remarkDirective() {
|
|
||||||
// @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()
|
|
||||||
|
|
||||||
const micromarkExtensions =
|
|
||||||
data.micromarkExtensions || (data.micromarkExtensions = [])
|
|
||||||
const fromMarkdownExtensions =
|
|
||||||
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
|
|
||||||
const toMarkdownExtensions =
|
|
||||||
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])
|
|
||||||
|
|
||||||
micromarkExtensions.push(directive())
|
|
||||||
fromMarkdownExtensions.push(directiveFromMarkdown())
|
|
||||||
toMarkdownExtensions.push(directiveToMarkdown())
|
|
||||||
}
|
|
||||||
|
|
39
lib/index.js
Normal file
39
lib/index.js
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/// <reference types="remark-parse" />
|
||||||
|
/// <reference types="remark-stringify" />
|
||||||
|
/// <reference types="mdast-util-directive" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('mdast').Root} Root
|
||||||
|
* @typedef {import('unified').Processor<Root>} Processor
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
||||||
|
import {directive} from 'micromark-extension-directive'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add support for generic directives.
|
||||||
|
*
|
||||||
|
* ###### Notes
|
||||||
|
*
|
||||||
|
* Doesn’t handle the directives: create your own plugin to do that.
|
||||||
|
*
|
||||||
|
* @returns {undefined}
|
||||||
|
* Nothing.
|
||||||
|
*/
|
||||||
|
export default function remarkDirective() {
|
||||||
|
// @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()
|
||||||
|
|
||||||
|
const micromarkExtensions =
|
||||||
|
data.micromarkExtensions || (data.micromarkExtensions = [])
|
||||||
|
const fromMarkdownExtensions =
|
||||||
|
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
|
||||||
|
const toMarkdownExtensions =
|
||||||
|
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])
|
||||||
|
|
||||||
|
micromarkExtensions.push(directive())
|
||||||
|
fromMarkdownExtensions.push(directiveFromMarkdown())
|
||||||
|
toMarkdownExtensions.push(directiveToMarkdown())
|
||||||
|
}
|
|
@ -29,6 +29,7 @@
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
|
"lib/",
|
||||||
"index.d.ts",
|
"index.d.ts",
|
||||||
"index.js"
|
"index.js"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue