MCPcopy
hub / github.com/docsifyjs/docsify / _initRenderer

Method _initRenderer

src/core/render/compiler.js:195–260  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

193 }
194
195 _initRenderer() {
196 const renderer = new marked.Renderer();
197 const { linkTarget, linkRel, router, contentBase } = this;
198 const _self = this;
199 const origin = {};
200
201 /**
202 * Render anchor tag
203 * @link https://github.com/markedjs/marked#overriding-renderer-methods
204 * @param {String} text Text content
205 * @param {Number} level Type of heading (h<level> tag)
206 * @returns {String} Heading element
207 */
208 origin.heading = renderer.heading = function (text, level) {
209 let { str, config } = getAndRemoveConfig(text);
210 const nextToc = { level, title: removeAtag(str) };
211
212 if (/<!-- {docsify-ignore} -->/g.test(str)) {
213 str = str.replace('<!-- {docsify-ignore} -->', '');
214 nextToc.title = removeAtag(str);
215 nextToc.ignoreSubHeading = true;
216 }
217
218 if (/{docsify-ignore}/g.test(str)) {
219 str = str.replace('{docsify-ignore}', '');
220 nextToc.title = removeAtag(str);
221 nextToc.ignoreSubHeading = true;
222 }
223
224 if (/<!-- {docsify-ignore-all} -->/g.test(str)) {
225 str = str.replace('<!-- {docsify-ignore-all} -->', '');
226 nextToc.title = removeAtag(str);
227 nextToc.ignoreAllSubs = true;
228 }
229
230 if (/{docsify-ignore-all}/g.test(str)) {
231 str = str.replace('{docsify-ignore-all}', '');
232 nextToc.title = removeAtag(str);
233 nextToc.ignoreAllSubs = true;
234 }
235
236 const slug = slugify(config.id || str);
237 const url = router.toURL(router.getCurrentPath(), { id: slug });
238 nextToc.slug = url;
239 _self.toc.push(nextToc);
240
241 return `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${str}</span></a></h${level}>`;
242 };
243
244 origin.code = highlightCodeCompiler({ renderer });
245 origin.link = linkCompiler({
246 renderer,
247 router,
248 linkTarget,
249 linkRel,
250 compilerClass: _self,
251 });
252 origin.paragraph = paragraphCompiler({ renderer });

Callers 1

constructorMethod · 0.95

Calls 11

getAndRemoveConfigFunction · 0.90
removeAtagFunction · 0.90
slugifyFunction · 0.90
highlightCodeCompilerFunction · 0.90
linkCompilerFunction · 0.90
paragraphCompilerFunction · 0.90
imageCompilerFunction · 0.90
taskListCompilerFunction · 0.90
taskListItemCompilerFunction · 0.90
toURLMethod · 0.45
getCurrentPathMethod · 0.45

Tested by

no test coverage detected