Skip to content

Commit

Permalink
Update hooks for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 3, 2020
1 parent 39a2f23 commit 110dd4e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
17 changes: 10 additions & 7 deletions packages/remark-parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ function parse(options) {
this.Parser = parse

function parse(doc) {
var settings = Object.assign({}, self.data('settings'), options)
// Note: these options are not in the readme.
// The goal is for them to be set by plugins on `data` instead of being
// passed by users.
settings.extensions = settings.micromarkExtensions
settings.mdastExtensions = settings.fromMarkdownExtensions
return fromMarkdown(doc, settings)
return fromMarkdown(
doc,
Object.assign({}, self.data('settings'), options, {
// Note: these options are not in the readme.
// The goal is for them to be set by plugins on `data` instead of being
// passed by users.
extensions: self.data('micromarkExtensions') || [],
mdastExtensions: self.data('fromMarkdownExtensions') || []
})
)
}
}
7 changes: 3 additions & 4 deletions packages/remark-parse/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ test('remark().parse(file)', function (t) {

t.test('extensions', function (st) {
var tree = unified()
.use(parse, {
micromarkExtensions: [gfmSyntax()],
fromMarkdownExtensions: [gfm]
})
.data('micromarkExtensions', [gfmSyntax()])
.data('fromMarkdownExtensions', [gfm])
.use(parse)
.parse('* [x] [email protected] ~~strikethrough~~')

remove(tree, true)
Expand Down
15 changes: 9 additions & 6 deletions packages/remark-stringify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ function stringify(options) {
this.Compiler = compile

function compile(tree) {
var settings = Object.assign({}, self.data('settings'), options)
// Note: this option is not in the readme.
// The goal is for it to be set by plugins on `data` instead of being
// passed by users.
settings.extensions = settings.toMarkdownExtensions
return toMarkdown(tree, settings)
return toMarkdown(
tree,
Object.assign({}, self.data('settings'), options, {
// Note: this option is not in the readme.
// The goal is for it to be set by plugins on `data` instead of being
// passed by users.
extensions: self.data('toMarkdownExtensions') || []
})
)
}
}
3 changes: 2 additions & 1 deletion packages/remark-stringify/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ test('stringify escapes', function (t) {

test('extensions', function (t) {
var doc = unified()
.use(stringify, {toMarkdownExtensions: [gfm()]})
.data('toMarkdownExtensions', [gfm()])
.use(stringify)
.stringify({
type: 'root',
children: [
Expand Down

0 comments on commit 110dd4e

Please sign in to comment.