Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Add new getParser public API
Browse files Browse the repository at this point in the history
  • Loading branch information
revin committed Nov 4, 2016
1 parent c0902bf commit 04d9675
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
26 changes: 16 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ var defaults = require('lodash.defaults')
var render = require('./lib/render')
var sanitize = require('./lib/sanitize')

var defaultOptions = {
sanitize: true,
linkify: true,
highlightSyntax: true,
prefixHeadingIds: true,
enableHeadingLinkIcons: true,
serveImagesWithCDN: false,
debug: false,
package: null
}

var marky = module.exports = function (markdown, options) {
var html

Expand All @@ -10,16 +21,7 @@ var marky = module.exports = function (markdown, options) {
}

options = options || {}
defaults(options, {
sanitize: true,
linkify: true,
highlightSyntax: true,
prefixHeadingIds: true,
enableHeadingLinkIcons: true,
serveImagesWithCDN: false,
debug: false,
package: null
})
defaults(options, defaultOptions)

var log = function (msg) {
if (options.debug) {
Expand All @@ -43,3 +45,7 @@ var marky = module.exports = function (markdown, options) {
marky.parsePackageDescription = function (description) {
return sanitize(render.renderPackageDescription(description))
}

marky.getParser = function (options) {
return render.getParser(defaults(options || {}, defaultOptions))
}
16 changes: 10 additions & 6 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ if (typeof process.browser === 'undefined') {
cleanup(highlighter.registry.grammars)
}

var render = module.exports = function (html, options) {
var render = module.exports = function (markdown, options) {
return render.getParser(options).render(markdown)
}

render.getParser = function (options) {
var mdOptions = {
html: true,
langPrefix: 'highlight ',
Expand Down Expand Up @@ -79,7 +83,11 @@ var render = module.exports = function (html, options) {
if (options.highlightSyntax) parser.use(codeWrap)
if (options.serveImagesWithCDN) parser.use(cdnImages, {package: options.package})

return githubLinkify(parser).render(html)
return githubLinkify(parser)
}

render.renderPackageDescription = function (description) {
return MD({html: true}).renderInline(description)
}

var mappings = {
Expand Down Expand Up @@ -108,7 +116,3 @@ function scopeNameFromLang (highlighter, lang) {

return name
}

render.renderPackageDescription = function (description) {
return MD({html: true}).renderInline(description)
}

0 comments on commit 04d9675

Please sign in to comment.