Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does PackageDescription mean here? feel like we may soon be removing this when we get rid of packagize.js with #282

otherwise this is a misleading name. shouldn't affect this PR, but we should change that if it means the full README

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the name this method has had since before I started working on marky; last I saw many months ago, the npm web site was using it for rendering package.json description fields into HTML for use in on package pages.

If they're not using it anymore, I'd be in favor of deprecating/removing it. People will be able to do basically the same thing by calling marky.getParser().renderInline(markdownSnippet), but honestly it wouldn't surprise me if nobody at all is using it anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, and this has absolutely nothing to do with the packagize stuff!

and finally, the only reason it shows up in the diff here is because I moved it up earlier in the file so it grouped the module exports together 😕

yay legacy

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)
}