Skip to content

Commit b6ca06b

Browse files
committed
Use ESM
1 parent c932721 commit b6ca06b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+205
-265
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
.DS_Store
2-
*.log
3-
.nyc_output/
41
coverage/
52
node_modules/
3+
*.log
4+
.DS_Store
65
yarn.lock
7-
mdast-util-to-markdown.min.js

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage/
2-
*.json
32
*.md

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./lib/index.js')
1+
export {toMarkdown} from './lib/index.js'

lib/configure.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
module.exports = configure
2-
3-
function configure(base, extension) {
1+
export function configure(base, extension) {
42
var index = -1
53
var key
64

lib/handle/blockquote.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
module.exports = blockquote
1+
import {containerFlow} from '../util/container-flow.js'
2+
import {indentLines} from '../util/indent-lines.js'
23

3-
var flow = require('../util/container-flow.js')
4-
var indentLines = require('../util/indent-lines.js')
5-
6-
function blockquote(node, _, context) {
4+
export function blockquote(node, _, context) {
75
var exit = context.enter('blockquote')
8-
var value = indentLines(flow(node, context), map)
6+
var value = indentLines(containerFlow(node, context), map)
97
exit()
108
return value
119
}

lib/handle/break.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
module.exports = hardBreak
1+
import {patternInScope} from '../util/pattern-in-scope.js'
22

3-
var patternInScope = require('../util/pattern-in-scope.js')
4-
5-
function hardBreak(node, _, context, safe) {
3+
export function hardBreak(node, _, context, safe) {
64
var index = -1
75

86
while (++index < context.unsafe.length) {

lib/handle/code.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
module.exports = code
2-
3-
var repeat = require('repeat-string')
4-
var streak = require('longest-streak')
5-
var formatCodeAsIndented = require('../util/format-code-as-indented.js')
6-
var checkFence = require('../util/check-fence.js')
7-
var indentLines = require('../util/indent-lines.js')
8-
var safe = require('../util/safe.js')
9-
10-
function code(node, _, context) {
1+
import repeat from 'repeat-string'
2+
import {longestStreak} from 'longest-streak'
3+
import {formatCodeAsIndented} from '../util/format-code-as-indented.js'
4+
import {checkFence} from '../util/check-fence.js'
5+
import {indentLines} from '../util/indent-lines.js'
6+
import {safe} from '../util/safe.js'
7+
8+
export function code(node, _, context) {
119
var marker = checkFence(context)
1210
var raw = node.value || ''
1311
var suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
@@ -20,7 +18,7 @@ function code(node, _, context) {
2018
exit = context.enter('codeIndented')
2119
value = indentLines(raw, map)
2220
} else {
23-
sequence = repeat(marker, Math.max(streak(raw, marker) + 1, 3))
21+
sequence = repeat(marker, Math.max(longestStreak(raw, marker) + 1, 3))
2422
exit = context.enter('codeFenced')
2523
value = sequence
2624

lib/handle/definition.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
module.exports = definition
1+
import {association} from '../util/association.js'
2+
import {checkQuote} from '../util/check-quote.js'
3+
import {safe} from '../util/safe.js'
24

3-
var association = require('../util/association.js')
4-
var checkQuote = require('../util/check-quote.js')
5-
var safe = require('../util/safe.js')
6-
7-
function definition(node, _, context) {
5+
export function definition(node, _, context) {
86
var marker = checkQuote(context)
97
var suffix = marker === '"' ? 'Quote' : 'Apostrophe'
108
var exit = context.enter('definition')

lib/handle/emphasis.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
module.exports = emphasis
2-
emphasis.peek = emphasisPeek
1+
import {checkEmphasis} from '../util/check-emphasis.js'
2+
import {containerPhrasing} from '../util/container-phrasing.js'
33

4-
var checkEmphasis = require('../util/check-emphasis.js')
5-
var phrasing = require('../util/container-phrasing.js')
4+
emphasis.peek = emphasisPeek
65

76
// To do: there are cases where emphasis cannot “form” depending on the
87
// previous or next character of sequences.
98
// There’s no way around that though, except for injecting zero-width stuff.
109
// Do we need to safeguard against that?
11-
function emphasis(node, _, context) {
10+
export function emphasis(node, _, context) {
1211
var marker = checkEmphasis(context)
1312
var exit = context.enter('emphasis')
14-
var value = phrasing(node, context, {before: marker, after: marker})
13+
var value = containerPhrasing(node, context, {before: marker, after: marker})
1514
exit()
1615
return marker + value + marker
1716
}

lib/handle/heading.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
module.exports = heading
1+
import repeat from 'repeat-string'
2+
import {formatHeadingAsSetext} from '../util/format-heading-as-setext.js'
3+
import {containerPhrasing} from '../util/container-phrasing.js'
24

3-
var repeat = require('repeat-string')
4-
var formatHeadingAsSetext = require('../util/format-heading-as-setext.js')
5-
var phrasing = require('../util/container-phrasing.js')
6-
7-
function heading(node, _, context) {
5+
export function heading(node, _, context) {
86
var rank = Math.max(Math.min(6, node.depth || 1), 1)
97
var exit
108
var subexit
@@ -14,7 +12,7 @@ function heading(node, _, context) {
1412
if (formatHeadingAsSetext(node, context)) {
1513
exit = context.enter('headingSetext')
1614
subexit = context.enter('phrasing')
17-
value = phrasing(node, context, {before: '\n', after: '\n'})
15+
value = containerPhrasing(node, context, {before: '\n', after: '\n'})
1816
subexit()
1917
exit()
2018

@@ -35,7 +33,7 @@ function heading(node, _, context) {
3533
sequence = repeat('#', rank)
3634
exit = context.enter('headingAtx')
3735
subexit = context.enter('phrasing')
38-
value = phrasing(node, context, {before: '# ', after: '\n'})
36+
value = containerPhrasing(node, context, {before: '# ', after: '\n'})
3937
value = value ? sequence + ' ' + value : sequence
4038
if (context.options.closeAtx) {
4139
value += ' ' + sequence

lib/handle/html.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
module.exports = html
21
html.peek = htmlPeek
32

4-
function html(node) {
3+
export function html(node) {
54
return node.value || ''
65
}
76

lib/handle/image-reference.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
module.exports = imageReference
2-
imageReference.peek = imageReferencePeek
1+
import {association} from '../util/association.js'
2+
import {safe} from '../util/safe.js'
33

4-
var association = require('../util/association.js')
5-
var safe = require('../util/safe.js')
4+
imageReference.peek = imageReferencePeek
65

7-
function imageReference(node, _, context) {
6+
export function imageReference(node, _, context) {
87
var type = node.referenceType
98
var exit = context.enter('imageReference')
109
var subexit = context.enter('label')

lib/handle/image.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
module.exports = image
2-
image.peek = imagePeek
1+
import {checkQuote} from '../util/check-quote.js'
2+
import {safe} from '../util/safe.js'
33

4-
var checkQuote = require('../util/check-quote.js')
5-
var safe = require('../util/safe.js')
4+
image.peek = imagePeek
65

7-
function image(node, _, context) {
6+
export function image(node, _, context) {
87
var quote = checkQuote(context)
98
var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
109
var exit = context.enter('image')

lib/handle/index.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
1-
exports.blockquote = require('./blockquote.js')
2-
exports.break = require('./break.js')
3-
exports.code = require('./code.js')
4-
exports.definition = require('./definition.js')
5-
exports.emphasis = require('./emphasis.js')
6-
exports.hardBreak = require('./break.js')
7-
exports.heading = require('./heading.js')
8-
exports.html = require('./html.js')
9-
exports.image = require('./image.js')
10-
exports.imageReference = require('./image-reference.js')
11-
exports.inlineCode = require('./inline-code.js')
12-
exports.link = require('./link.js')
13-
exports.linkReference = require('./link-reference.js')
14-
exports.list = require('./list.js')
15-
exports.listItem = require('./list-item.js')
16-
exports.paragraph = require('./paragraph.js')
17-
exports.root = require('./root.js')
18-
exports.strong = require('./strong.js')
19-
exports.text = require('./text.js')
20-
exports.thematicBreak = require('./thematic-break.js')
1+
import {blockquote} from './blockquote.js'
2+
import {hardBreak} from './break.js'
3+
import {code} from './code.js'
4+
import {definition} from './definition.js'
5+
import {emphasis} from './emphasis.js'
6+
import {heading} from './heading.js'
7+
import {html} from './html.js'
8+
import {image} from './image.js'
9+
import {imageReference} from './image-reference.js'
10+
import {inlineCode} from './inline-code.js'
11+
import {link} from './link.js'
12+
import {linkReference} from './link-reference.js'
13+
import {list} from './list.js'
14+
import {listItem} from './list-item.js'
15+
import {paragraph} from './paragraph.js'
16+
import {root} from './root.js'
17+
import {strong} from './strong.js'
18+
import {text} from './text.js'
19+
import {thematicBreak} from './thematic-break.js'
20+
21+
export const handle = {
22+
blockquote,
23+
break: hardBreak,
24+
code,
25+
definition,
26+
emphasis,
27+
hardBreak,
28+
heading,
29+
html,
30+
image,
31+
imageReference,
32+
inlineCode,
33+
link,
34+
linkReference,
35+
list,
36+
listItem,
37+
paragraph,
38+
root,
39+
strong,
40+
text,
41+
thematicBreak
42+
}

lib/handle/inline-code.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
module.exports = inlineCode
2-
inlineCode.peek = inlineCodePeek
1+
import {patternCompile} from '../util/pattern-compile.js'
32

4-
var patternCompile = require('../util/pattern-compile.js')
3+
inlineCode.peek = inlineCodePeek
54

6-
function inlineCode(node, parent, context) {
5+
export function inlineCode(node, parent, context) {
76
var value = node.value || ''
87
var sequence = '`'
98
var index = -1

lib/handle/link-reference.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
module.exports = linkReference
2-
linkReference.peek = linkReferencePeek
1+
import {association} from '../util/association.js'
2+
import {containerPhrasing} from '../util/container-phrasing.js'
3+
import {safe} from '../util/safe.js'
34

4-
var association = require('../util/association.js')
5-
var phrasing = require('../util/container-phrasing.js')
6-
var safe = require('../util/safe.js')
5+
linkReference.peek = linkReferencePeek
76

8-
function linkReference(node, _, context) {
7+
export function linkReference(node, _, context) {
98
var type = node.referenceType
109
var exit = context.enter('linkReference')
1110
var subexit = context.enter('label')
12-
var text = phrasing(node, context, {before: '[', after: ']'})
11+
var text = containerPhrasing(node, context, {before: '[', after: ']'})
1312
var value = '[' + text + ']'
1413
var reference
1514
var stack

lib/handle/link.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
module.exports = link
2-
link.peek = linkPeek
1+
import {checkQuote} from '../util/check-quote.js'
2+
import {formatLinkAsAutolink} from '../util/format-link-as-autolink.js'
3+
import {containerPhrasing} from '../util/container-phrasing.js'
4+
import {safe} from '../util/safe.js'
35

4-
var checkQuote = require('../util/check-quote.js')
5-
var formatLinkAsAutolink = require('../util/format-link-as-autolink.js')
6-
var phrasing = require('../util/container-phrasing.js')
7-
var safe = require('../util/safe.js')
6+
link.peek = linkPeek
87

9-
function link(node, _, context) {
8+
export function link(node, _, context) {
109
var quote = checkQuote(context)
1110
var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
1211
var exit
@@ -19,15 +18,17 @@ function link(node, _, context) {
1918
stack = context.stack
2019
context.stack = []
2120
exit = context.enter('autolink')
22-
value = '<' + phrasing(node, context, {before: '<', after: '>'}) + '>'
21+
value =
22+
'<' + containerPhrasing(node, context, {before: '<', after: '>'}) + '>'
2323
exit()
2424
context.stack = stack
2525
return value
2626
}
2727

2828
exit = context.enter('link')
2929
subexit = context.enter('label')
30-
value = '[' + phrasing(node, context, {before: '[', after: ']'}) + ']('
30+
value =
31+
'[' + containerPhrasing(node, context, {before: '[', after: ']'}) + ']('
3132
subexit()
3233

3334
if (

lib/handle/list-item.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
module.exports = listItem
1+
import repeat from 'repeat-string'
2+
import {checkBullet} from '../util/check-bullet.js'
3+
import {checkListItemIndent} from '../util/check-list-item-indent.js'
4+
import {containerFlow} from '../util/container-flow.js'
5+
import {indentLines} from '../util/indent-lines.js'
26

3-
var repeat = require('repeat-string')
4-
var checkBullet = require('../util/check-bullet.js')
5-
var checkListItemIndent = require('../util/check-list-item-indent.js')
6-
var flow = require('../util/container-flow.js')
7-
var indentLines = require('../util/indent-lines.js')
8-
9-
function listItem(node, parent, context) {
7+
export function listItem(node, parent, context) {
108
var bullet = checkBullet(context)
119
var listItemIndent = checkListItemIndent(context)
1210
var size
@@ -32,7 +30,7 @@ function listItem(node, parent, context) {
3230
}
3331

3432
exit = context.enter('listItem')
35-
value = indentLines(flow(node, context), map)
33+
value = indentLines(containerFlow(node, context), map)
3634
exit()
3735

3836
return value

lib/handle/list.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
module.exports = list
1+
import {containerFlow} from '../util/container-flow.js'
22

3-
var flow = require('../util/container-flow.js')
4-
5-
function list(node, _, context) {
3+
export function list(node, _, context) {
64
var exit = context.enter('list')
7-
var value = flow(node, context)
5+
var value = containerFlow(node, context)
86
exit()
97
return value
108
}

lib/handle/paragraph.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
module.exports = paragraph
1+
import {containerPhrasing} from '../util/container-phrasing.js'
22

3-
var phrasing = require('../util/container-phrasing.js')
4-
5-
function paragraph(node, _, context) {
3+
export function paragraph(node, _, context) {
64
var exit = context.enter('paragraph')
75
var subexit = context.enter('phrasing')
8-
var value = phrasing(node, context, {before: '\n', after: '\n'})
6+
var value = containerPhrasing(node, context, {before: '\n', after: '\n'})
97
subexit()
108
exit()
119
return value

lib/handle/root.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
module.exports = root
1+
import {containerFlow} from '../util/container-flow.js'
22

3-
var flow = require('../util/container-flow.js')
4-
5-
function root(node, _, context) {
6-
return flow(node, context)
3+
export function root(node, _, context) {
4+
return containerFlow(node, context)
75
}

0 commit comments

Comments
 (0)