Skip to content

Commit 2e35fca

Browse files
committed
Change to expose functions
1 parent 4c905b9 commit 2e35fca

File tree

3 files changed

+56
-40
lines changed

3 files changed

+56
-40
lines changed

lib/index.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
1111
*/
1212

13-
// To do: next major: expose functions.
14-
1513
/**
1614
* List of constructs that occur in phrasing (paragraphs, headings), but cannot
1715
* contain strikethrough.
@@ -34,30 +32,38 @@ const constructsWithoutStrikethrough = [
3432
handleDelete.peek = peekDelete
3533

3634
/**
37-
* Extension for `mdast-util-from-markdown` to enable GFM strikethrough.
35+
* Create an extension for `mdast-util-from-markdown` to enable GFM
36+
* strikethrough in markdown.
3837
*
39-
* @type {FromMarkdownExtension}
38+
* @returns {FromMarkdownExtension}
39+
* Extension for `mdast-util-from-markdown` to enable GFM strikethrough.
4040
*/
41-
export const gfmStrikethroughFromMarkdown = {
42-
canContainEols: ['delete'],
43-
enter: {strikethrough: enterStrikethrough},
44-
exit: {strikethrough: exitStrikethrough}
41+
export function gfmStrikethroughFromMarkdown() {
42+
return {
43+
canContainEols: ['delete'],
44+
enter: {strikethrough: enterStrikethrough},
45+
exit: {strikethrough: exitStrikethrough}
46+
}
4547
}
4648

4749
/**
48-
* Extension for `mdast-util-to-markdown` to enable GFM strikethrough.
50+
* Create an extension for `mdast-util-to-markdown` to enable GFM
51+
* strikethrough in markdown.
4952
*
50-
* @type {ToMarkdownExtension}
53+
* @returns {ToMarkdownExtension}
54+
* Extension for `mdast-util-to-markdown` to enable GFM strikethrough.
5155
*/
52-
export const gfmStrikethroughToMarkdown = {
53-
unsafe: [
54-
{
55-
character: '~',
56-
inConstruct: 'phrasing',
57-
notInConstruct: constructsWithoutStrikethrough
58-
}
59-
],
60-
handlers: {delete: handleDelete}
56+
export function gfmStrikethroughToMarkdown() {
57+
return {
58+
unsafe: [
59+
{
60+
character: '~',
61+
inConstruct: 'phrasing',
62+
notInConstruct: constructsWithoutStrikethrough
63+
}
64+
],
65+
handlers: {delete: handleDelete}
66+
}
6167
}
6268

6369
/**

readme.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`gfmStrikethroughFromMarkdown`](#gfmstrikethroughfrommarkdown)
21-
* [`gfmStrikethroughToMarkdown`](#gfmstrikethroughtomarkdown)
20+
* [`gfmStrikethroughFromMarkdown()`](#gfmstrikethroughfrommarkdown)
21+
* [`gfmStrikethroughToMarkdown()`](#gfmstrikethroughtomarkdown)
2222
* [HTML](#html)
2323
* [Syntax](#syntax)
2424
* [Syntax tree](#syntax-tree)
@@ -106,12 +106,12 @@ const doc = await fs.readFile('example.md')
106106

107107
const tree = fromMarkdown(doc, {
108108
extensions: [gfmStrikethrough()],
109-
mdastExtensions: [gfmStrikethroughFromMarkdown]
109+
mdastExtensions: [gfmStrikethroughFromMarkdown()]
110110
})
111111

112112
console.log(tree)
113113

114-
const out = toMarkdown(tree, {extensions: [gfmStrikethroughToMarkdown]})
114+
const out = toMarkdown(tree, {extensions: [gfmStrikethroughToMarkdown()]})
115115

116116
console.log(out)
117117
```
@@ -148,15 +148,25 @@ This package exports the identifiers
148148
[`gfmStrikethroughToMarkdown`][api-gfm-strikethrough-to-markdown].
149149
There is no default export.
150150

151-
### `gfmStrikethroughFromMarkdown`
151+
### `gfmStrikethroughFromMarkdown()`
152152

153-
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable
154-
GFM strikethrough ([`FromMarkdownExtension`][from-markdown-extension]).
153+
Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown]
154+
to enable GFM strikethrough in markdown.
155155

156-
### `gfmStrikethroughToMarkdown`
156+
###### Returns
157157

158-
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to enable
159-
GFM strikethrough ([`ToMarkdownExtension`][to-markdown-extension]).
158+
Extension for `mdast-util-from-markdown` to enable GFM strikethrough
159+
([`FromMarkdownExtension`][from-markdown-extension]).
160+
161+
### `gfmStrikethroughToMarkdown()`
162+
163+
Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to
164+
enable GFM strikethrough in markdown.
165+
166+
###### Returns
167+
168+
Extension for `mdast-util-to-markdown` to enable GFM strikethrough
169+
([`ToMarkdownExtension`][to-markdown-extension]).
160170

161171
## HTML
162172

test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ test('core', async function (t) {
1818
})
1919
})
2020

21-
test('gfmStrikethroughFromMarkdown', async function (t) {
21+
test('gfmStrikethroughFromMarkdown()', async function (t) {
2222
await t.test('should support strikethrough', async function () {
2323
const tree = fromMarkdown('a ~~b~~ c.', {
2424
extensions: [gfmStrikethrough()],
25-
mdastExtensions: [gfmStrikethroughFromMarkdown]
25+
mdastExtensions: [gfmStrikethroughFromMarkdown()]
2626
})
2727

2828
removePosition(tree, {force: true})
@@ -45,7 +45,7 @@ test('gfmStrikethroughFromMarkdown', async function (t) {
4545
await t.test('should support strikethrough w/ eols', async function () {
4646
const tree = fromMarkdown('a ~~b\nc~~ d.', {
4747
extensions: [gfmStrikethrough()],
48-
mdastExtensions: [gfmStrikethroughFromMarkdown]
48+
mdastExtensions: [gfmStrikethroughFromMarkdown()]
4949
})
5050

5151
removePosition(tree, {force: true})
@@ -66,7 +66,7 @@ test('gfmStrikethroughFromMarkdown', async function (t) {
6666
})
6767
})
6868

69-
test('gfmStrikethroughToMarkdown', async function (t) {
69+
test('gfmStrikethroughToMarkdown()', async function (t) {
7070
await t.test('should serialize strikethrough', async function () {
7171
assert.deepEqual(
7272
toMarkdown(
@@ -78,7 +78,7 @@ test('gfmStrikethroughToMarkdown', async function (t) {
7878
{type: 'text', value: ' c.'}
7979
]
8080
},
81-
{extensions: [gfmStrikethroughToMarkdown]}
81+
{extensions: [gfmStrikethroughToMarkdown()]}
8282
),
8383
'a ~~b~~ c.\n'
8484
)
@@ -95,7 +95,7 @@ test('gfmStrikethroughToMarkdown', async function (t) {
9595
{type: 'text', value: ' d.'}
9696
]
9797
},
98-
{extensions: [gfmStrikethroughToMarkdown]}
98+
{extensions: [gfmStrikethroughToMarkdown()]}
9999
),
100100
'a ~~b\nc~~ d.\n'
101101
)
@@ -116,7 +116,7 @@ test('gfmStrikethroughToMarkdown', async function (t) {
116116
}
117117
]
118118
},
119-
{extensions: [gfmStrikethroughToMarkdown]}
119+
{extensions: [gfmStrikethroughToMarkdown()]}
120120
),
121121
'[](~a)\n'
122122
)
@@ -138,7 +138,7 @@ test('gfmStrikethroughToMarkdown', async function (t) {
138138
}
139139
]
140140
},
141-
{extensions: [gfmStrikethroughToMarkdown]}
141+
{extensions: [gfmStrikethroughToMarkdown()]}
142142
),
143143
'[link text](~a)\n'
144144
)
@@ -159,7 +159,7 @@ test('gfmStrikethroughToMarkdown', async function (t) {
159159
}
160160
]
161161
},
162-
{extensions: [gfmStrikethroughToMarkdown]}
162+
{extensions: [gfmStrikethroughToMarkdown()]}
163163
),
164164
'[][~a]\n'
165165
)
@@ -181,7 +181,7 @@ test('gfmStrikethroughToMarkdown', async function (t) {
181181
}
182182
]
183183
},
184-
{extensions: [gfmStrikethroughToMarkdown]}
184+
{extensions: [gfmStrikethroughToMarkdown()]}
185185
),
186186
'[](# "~a")\n'
187187
)
@@ -206,7 +206,7 @@ test('gfmStrikethroughToMarkdown', async function (t) {
206206
},
207207
{
208208
quote: "'",
209-
extensions: [gfmStrikethroughToMarkdown]
209+
extensions: [gfmStrikethroughToMarkdown()]
210210
}
211211
),
212212
"[](# '~a')\n"

0 commit comments

Comments
 (0)