Skip to content

Commit

Permalink
Change to expose functions
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 25, 2023
1 parent 2f4630f commit 6da41ea
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
34 changes: 18 additions & 16 deletions dev/lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/

// To do: next major: expose function to make extension.

/**
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM task list items when serializing to HTML.
* Create an HTML extension for `micromark` to support GFM task list items when
* serializing to HTML.
*
* @type {HtmlExtension}
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM task list items when serializing to HTML.
*/
export const gfmTaskListItemHtml = {
enter: {
taskListCheck() {
this.tag('<input type="checkbox" disabled="" ')
}
},
exit: {
taskListCheck() {
this.tag('/>')
export function gfmTaskListItemHtml() {
return {
enter: {
taskListCheck() {
this.tag('<input type="checkbox" disabled="" ')
}
},
taskListCheckValueChecked() {
this.tag('checked="" ')
exit: {
taskListCheck() {
this.tag('/>')
},
taskListCheckValueChecked() {
this.tag('checked="" ')
}
}
}
}
16 changes: 9 additions & 7 deletions dev/lib/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import {types} from 'micromark-util-symbol/types.js'

const tasklistCheck = {tokenize: tokenizeTasklistCheck}

// To do: next major: expose function to make extension.

/**
* Extension for `micromark` that can be passed in `extensions`, to
* enable GFM task list items syntax.
* Create an HTML extension for `micromark` to support GFM task list items
* syntax.
*
* @type {Extension}
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions`, to enable
* GFM task list items syntax.
*/
export const gfmTaskListItem = {
text: {[codes.leftSquareBracket]: tasklistCheck}
export function gfmTaskListItem() {
return {
text: {[codes.leftSquareBracket]: tasklistCheck}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ import {
} from 'micromark-extension-gfm-task-list-item'

const output = micromark('* [x] a\n* [ ] b', {
extensions: [gfmTaskListItem],
htmlExtensions: [gfmTaskListItemHtml]
extensions: [gfmTaskListItem()],
htmlExtensions: [gfmTaskListItemHtml()]
})

console.log(output)
Expand Down
12 changes: 6 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ test('markdown -> html (micromark)', async function (t) {
await t.test('should not support laziness (1)', async function () {
assert.deepEqual(
micromark('*\n [x]', {
extensions: [gfmTaskListItem],
htmlExtensions: [gfmTaskListItemHtml]
extensions: [gfmTaskListItem()],
htmlExtensions: [gfmTaskListItemHtml()]
}),
'<ul>\n<li>[x]</li>\n</ul>'
)
Expand All @@ -32,8 +32,8 @@ test('markdown -> html (micromark)', async function (t) {
await t.test('should not support laziness (2)', async function () {
assert.deepEqual(
micromark('*\n[x]', {
extensions: [gfmTaskListItem],
htmlExtensions: [gfmTaskListItemHtml]
extensions: [gfmTaskListItem()],
htmlExtensions: [gfmTaskListItemHtml()]
}),
'<ul>\n<li></li>\n</ul>\n<p>[x]</p>'
)
Expand Down Expand Up @@ -62,8 +62,8 @@ test('fixtures', async function (t) {
const input = String(await fs.readFile(new URL(d, base)))
const expected = String(await fs.readFile(new URL(name + '.html', base)))
let actual = micromark(controlPictures(input), {
extensions: [gfmTaskListItem],
htmlExtensions: [gfmTaskListItemHtml]
extensions: [gfmTaskListItem()],
htmlExtensions: [gfmTaskListItemHtml()]
})

if (actual && !/\n$/.test(actual)) {
Expand Down

0 comments on commit 6da41ea

Please sign in to comment.