MCPcopy
hub / github.com/jsdoc/jsdoc / getParseFunction

Function getParseFunction

lib/jsdoc/util/markdown.js:188–266  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

186 * returns the resulting HTML.
187 */
188function 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(/&#39;/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);

Callers 1

markdown.jsFile · 0.85

Calls 7

getHighlighterFunction · 0.85
escapeUnderscoresFunction · 0.85
escapeUrlsFunction · 0.85
unescapeUrlsFunction · 0.85
unencodeQuotesFunction · 0.85
renderMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…