* Retrieve a function that accepts a single parameter containing Markdown source. The function uses * the specified parser to transform the Markdown source to HTML, then returns the HTML as a string. * * @private * @param {String} parserName The name of the selected parser. * @param {Object} [c
(parserName, conf)
| 186 | * returns the resulting HTML. |
| 187 | */ |
| 188 | function getParseFunction(parserName, conf) { |
| 189 | let highlighter; |
| 190 | let parserFunction; |
| 191 | let renderer; |
| 192 | |
| 193 | conf = conf || {}; |
| 194 | highlighter = getHighlighter(conf); |
| 195 | |
| 196 | switch (parserName) { |
| 197 | case parserNames.marked: |
| 198 | if (conf.hardwrap) { |
| 199 | marked.setOptions({breaks: true}); |
| 200 | } |
| 201 | |
| 202 | // Marked generates an "id" attribute for headers; this custom renderer suppresses it |
| 203 | renderer = new marked.Renderer(); |
| 204 | |
| 205 | if (!conf.idInHeadings) { |
| 206 | renderer.heading = (text, level) => util.format('<h%s>%s</h%s>', level, text, level); |
| 207 | } |
| 208 | |
| 209 | renderer.code = highlighter; |
| 210 | |
| 211 | parserFunction = source => { |
| 212 | let result; |
| 213 | |
| 214 | source = escapeUnderscores(source); |
| 215 | source = escapeUrls(source); |
| 216 | |
| 217 | result = marked(source, { renderer: renderer }) |
| 218 | .replace(/\s+$/, '') |
| 219 | .replace(/'/g, "'"); |
| 220 | |
| 221 | result = unescapeUrls(result); |
| 222 | result = unencodeQuotes(result); |
| 223 | |
| 224 | return result; |
| 225 | }; |
| 226 | parserFunction._parser = parserNames.marked; |
| 227 | |
| 228 | return parserFunction; |
| 229 | |
| 230 | case parserNames.markdownit: |
| 231 | renderer = new MarkdownIt({ |
| 232 | breaks: Boolean(conf.hardwrap), |
| 233 | highlight: highlighter, |
| 234 | html: true |
| 235 | }); |
| 236 | |
| 237 | if (conf.idInHeadings) { |
| 238 | renderer.use(mda, { tabIndex: false }); |
| 239 | } |
| 240 | |
| 241 | parserFunction = source => { |
| 242 | let result; |
| 243 | |
| 244 | source = escapeUrls(source); |
| 245 | source = escapeInlineTagBackslashes(source); |
no test coverage detected
searching dependent graphs…