Skip to content

Commit 6c7d519

Browse files
committed
Fix to not serialize as link (auto), code (indented)
1 parent 72f9af8 commit 6c7d519

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
"dependencies": {
3636
"mdast-util-mdx-expression": "~0.1.0",
3737
"mdast-util-mdx-jsx": "~0.1.0",
38-
"mdast-util-mdxjs-esm": "~0.1.0"
38+
"mdast-util-mdxjs-esm": "~0.1.0",
39+
"mdast-util-to-markdown": "^0.6.1"
3940
},
4041
"devDependencies": {
42+
"mdast-util-from-markdown": "^0.8.0",
4143
"micromark-extension-mdx": "^0.1.0",
4244
"micromark-extension-mdxjs": "^0.1.0",
4345
"nyc": "^15.0.0",

test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,18 @@ test('mdast -> markdown', function (t) {
198198
'should support expressions'
199199
)
200200

201+
t.deepEqual(
202+
toMarkdown(
203+
{
204+
type: 'link',
205+
url: 'tel:123',
206+
children: [{type: 'text', value: 'tel:123'}]
207+
},
208+
{extensions: [mdx.toMarkdown]}
209+
),
210+
'[tel:123](tel:123)\n',
211+
'should use link (resource) instead of link (auto)'
212+
)
213+
201214
t.end()
202215
})

to-markdown.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
var expression = require('mdast-util-mdx-expression/to-markdown')
22
var jsx = require('mdast-util-mdx-jsx/to-markdown')
33
var esm = require('mdast-util-mdxjs-esm/to-markdown')
4-
5-
module.exports = configure()
6-
7-
function configure() {
8-
var extensions = [expression, jsx, esm]
9-
var index = -1
10-
var unsafe = []
11-
var handlers = {}
12-
var extension
13-
14-
while (++index < extensions.length) {
15-
extension = extensions[index]
16-
unsafe = unsafe.concat(extension.unsafe || [])
17-
// istanbul ignore next - handlers always exists, for now.
18-
handlers = Object.assign(handlers, extension.handlers || {})
19-
}
20-
21-
return {unsafe: unsafe, handlers: handlers}
22-
}
4+
var configure = require('mdast-util-to-markdown/lib/configure')
5+
6+
var base = configure(
7+
{handlers: {}, join: [], unsafe: [], options: {}},
8+
{extensions: [expression, jsx, esm]}
9+
)
10+
11+
module.exports = Object.assign(base.options, {
12+
handlers: base.handlers,
13+
join: base.join,
14+
unsafe: base.unsafe
15+
})

0 commit comments

Comments
 (0)