Skip to content

Commit

Permalink
Refactor to move code to lib/
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 18, 2023
1 parent bceb8b8 commit 4bf0329
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
46 changes: 2 additions & 44 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,5 @@
/// <reference types="remark-parse" />
/// <reference types="remark-stringify" />

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast-util-gfm').Options} MdastOptions
* @typedef {import('micromark-extension-gfm').Options} MicromarkOptions
* @typedef {import('unified').Processor<Root>} Processor
*/

/**
* @typedef {MicromarkOptions & MdastOptions} Options
* Configuration.
*/

import {gfmFromMarkdown, gfmToMarkdown} from 'mdast-util-gfm'
import {gfm} from 'micromark-extension-gfm'

/** @type {Options} */
const emptyOptions = {}

/**
* Add support GFM (autolink literals, footnotes, strikethrough, tables, tasklists).
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {undefined}
* Nothing.
* @typedef {import('./lib/index.js').Options} Options
*/
export default function remarkGfm(options) {
// @ts-expect-error: TS is wrong about `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {Processor} */ (this)
const settings = options || emptyOptions
const data = self.data()

const micromarkExtensions =
data.micromarkExtensions || (data.micromarkExtensions = [])
const fromMarkdownExtensions =
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
const toMarkdownExtensions =
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])

micromarkExtensions.push(gfm(settings))
fromMarkdownExtensions.push(gfmFromMarkdown())
toMarkdownExtensions.push(gfmToMarkdown(settings))
}
export {default} from './lib/index.js'
47 changes: 47 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// <reference types="remark-parse" />
/// <reference types="remark-stringify" />

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast-util-gfm').Options} MdastOptions
* @typedef {import('micromark-extension-gfm').Options} MicromarkOptions
* @typedef {import('unified').Processor<Root>} Processor
*/

/**
* @typedef {MicromarkOptions & MdastOptions} Options
* Configuration.
*/

import {gfmFromMarkdown, gfmToMarkdown} from 'mdast-util-gfm'
import {gfm} from 'micromark-extension-gfm'

/** @type {Options} */
const emptyOptions = {}

/**
* Add support GFM (autolink literals, footnotes, strikethrough, tables, tasklists).
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {undefined}
* Nothing.
*/
export default function remarkGfm(options) {
// @ts-expect-error: TS is wrong about `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {Processor} */ (this)
const settings = options || emptyOptions
const data = self.data()

const micromarkExtensions =
data.micromarkExtensions || (data.micromarkExtensions = [])
const fromMarkdownExtensions =
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
const toMarkdownExtensions =
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])

micromarkExtensions.push(gfm(settings))
fromMarkdownExtensions.push(gfmFromMarkdown())
toMarkdownExtensions.push(gfmToMarkdown(settings))
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
Expand Down

0 comments on commit 4bf0329

Please sign in to comment.