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 bccecaf commit 7544a4b
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
*.log
.DS_Store
yarn.lock
!/index.d.ts
14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type {HtmlOptions as GfmFootnoteHtmlOptions} from 'micromark-extension-gfm-footnote'
import type {Options as GfmStrikethroughOptions} from 'micromark-extension-gfm-strikethrough'

export {gfm, gfmHtml} from './lib/index.js'

/**
* Configuration for `gfmHtml` of `micromark-extension-gfm`.
*/
export interface HtmlOptions extends GfmFootnoteHtmlOptions {}

/**
* Configuration for `gfm` of `micromark-extension-gfm`.
*/
export interface Options extends GfmStrikethroughOptions {}
71 changes: 2 additions & 69 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,2 @@
/**
* @typedef {import('micromark-extension-gfm-footnote').HtmlOptions} HtmlOptions
* @typedef {import('micromark-extension-gfm-strikethrough').Options} Options
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/

import {
combineExtensions,
combineHtmlExtensions
} from 'micromark-util-combine-extensions'
import {
gfmAutolinkLiteral,
gfmAutolinkLiteralHtml
} from 'micromark-extension-gfm-autolink-literal'
import {gfmFootnote, gfmFootnoteHtml} from 'micromark-extension-gfm-footnote'
import {
gfmStrikethrough,
gfmStrikethroughHtml
} from 'micromark-extension-gfm-strikethrough'
import {gfmTable, gfmTableHtml} from 'micromark-extension-gfm-table'
import {gfmTagfilterHtml} from 'micromark-extension-gfm-tagfilter'
import {
gfmTaskListItem,
gfmTaskListItemHtml
} from 'micromark-extension-gfm-task-list-item'

/**
* Create an extension for `micromark` to enable GFM syntax.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
*
* Passed to `micromark-extens-gfm-strikethrough`.
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* syntax.
*/
export function gfm(options) {
return combineExtensions([
gfmAutolinkLiteral(),
gfmFootnote(),
gfmStrikethrough(options),
gfmTable(),
gfmTaskListItem()
])
}

/**
* Create an extension for `micromark` to support GFM when serializing to HTML.
*
* @param {HtmlOptions | null | undefined} [options]
* Configuration (optional).
*
* Passed to `micromark-extens-gfm-footnote`.
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM when serializing to HTML.
*/
export function gfmHtml(options) {
return combineHtmlExtensions([
gfmAutolinkLiteralHtml(),
gfmFootnoteHtml(options),
gfmStrikethroughHtml(),
gfmTableHtml(),
gfmTagfilterHtml(),
gfmTaskListItemHtml()
])
}
// Note: types exposed from `index.d.ts`.
export {gfm, gfmHtml} from './lib/index.js'
67 changes: 67 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @import {Options, HtmlOptions} from 'micromark-extension-gfm'
* @import {Extension, HtmlExtension} from 'micromark-util-types'
*/

import {
combineExtensions,
combineHtmlExtensions
} from 'micromark-util-combine-extensions'
import {
gfmAutolinkLiteral,
gfmAutolinkLiteralHtml
} from 'micromark-extension-gfm-autolink-literal'
import {gfmFootnote, gfmFootnoteHtml} from 'micromark-extension-gfm-footnote'
import {
gfmStrikethrough,
gfmStrikethroughHtml
} from 'micromark-extension-gfm-strikethrough'
import {gfmTable, gfmTableHtml} from 'micromark-extension-gfm-table'
import {gfmTagfilterHtml} from 'micromark-extension-gfm-tagfilter'
import {
gfmTaskListItem,
gfmTaskListItemHtml
} from 'micromark-extension-gfm-task-list-item'

/**
* Create an extension for `micromark` to enable GFM syntax.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
*
* Passed to `micromark-extens-gfm-strikethrough`.
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* syntax.
*/
export function gfm(options) {
return combineExtensions([
gfmAutolinkLiteral(),
gfmFootnote(),
gfmStrikethrough(options),
gfmTable(),
gfmTaskListItem()
])
}

/**
* Create an extension for `micromark` to support GFM when serializing to HTML.
*
* @param {HtmlOptions | null | undefined} [options]
* Configuration (optional).
*
* Passed to `micromark-extens-gfm-footnote`.
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM when serializing to HTML.
*/
export function gfmHtml(options) {
return combineHtmlExtensions([
gfmAutolinkLiteralHtml(),
gfmFootnoteHtml(options),
gfmStrikethroughHtml(),
gfmTableHtml(),
gfmTagfilterHtml(),
gfmTaskListItemHtml()
])
}
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"type": "module",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
Expand Down Expand Up @@ -93,6 +94,29 @@
},
"xo": {
"overrides": [
{
"files": [
"**/*.d.ts"
],
"rules": {
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"extendDefaults": true
}
],
"@typescript-eslint/consistent-type-definitions": [
"error",
"interface"
]
}
},
{
"files": [
"{test,script}/**/*.js"
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"strict": true,
"target": "es2022"
},
"include": ["**/*.js"],
"exclude": ["coverage/", "node_modules/"]
"exclude": ["coverage/", "node_modules/"],
"include": ["**/*.js", "index.d.ts"]
}

0 comments on commit 7544a4b

Please sign in to comment.