Skip to content

Commit

Permalink
Refactor to use mdast-util-to-markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Dec 10, 2020
1 parent c1f141a commit c287df8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"mdast-util-gfm-autolink-literal": "^0.1.0",
"mdast-util-gfm-strikethrough": "^0.2.0",
"mdast-util-gfm-table": "^0.1.0",
"mdast-util-gfm-task-list-item": "^0.1.0"
"mdast-util-gfm-task-list-item": "^0.1.0",
"mdast-util-to-markdown": "^0.6.1"
},
"devDependencies": {
"github-slugger": "^1.0.0",
"hast-util-to-html": "^7.0.0",
"mdast-util-from-markdown": "^0.8.0",
"mdast-util-to-hast": "^10.0.0",
"mdast-util-to-markdown": "^0.5.0",
"micromark-extension-gfm": "^0.3.0",
"node-fetch": "^2.0.0",
"nyc": "^15.0.0",
Expand Down
31 changes: 12 additions & 19 deletions to-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@ var autolinkLiteral = require('mdast-util-gfm-autolink-literal/to-markdown')
var strikethrough = require('mdast-util-gfm-strikethrough/to-markdown')
var table = require('mdast-util-gfm-table/to-markdown')
var taskListItem = require('mdast-util-gfm-task-list-item/to-markdown')
var configure = require('mdast-util-to-markdown/lib/configure')

module.exports = toMarkdown

function toMarkdown(options) {
var extensions = [
autolinkLiteral,
strikethrough,
table(options),
taskListItem
]
var length = extensions.length
var index = -1
var extension
var unsafe = []
var handlers = {}
var config = configure(
{handlers: {}, join: [], unsafe: [], options: {}},
{
extensions: [autolinkLiteral, strikethrough, table(options), taskListItem]
}
)

while (++index < length) {
extension = extensions[index]
// istanbul ignore next - unsafe always exists, for now.
unsafe = unsafe.concat(extension.unsafe || [])
handlers = Object.assign(handlers, extension.handlers || {})
}

return {unsafe: unsafe, handlers: handlers}
return Object.assign(config.options, {
handlers: config.handlers,
join: config.join,
unsafe: config.unsafe
})
}

0 comments on commit c287df8

Please sign in to comment.