(config, router)
| 60 | |
| 61 | export class Compiler { |
| 62 | constructor(config, router) { |
| 63 | this.config = config; |
| 64 | this.router = router; |
| 65 | this.cacheTree = {}; |
| 66 | this.toc = []; |
| 67 | this.cacheTOC = {}; |
| 68 | this.linkTarget = config.externalLinkTarget || '_blank'; |
| 69 | this.linkRel = |
| 70 | this.linkTarget === '_blank' ? config.externalLinkRel || 'noopener' : ''; |
| 71 | this.contentBase = router.getBasePath(); |
| 72 | |
| 73 | const renderer = this._initRenderer(); |
| 74 | this.heading = renderer.heading; |
| 75 | let compile; |
| 76 | const mdConf = config.markdown || {}; |
| 77 | |
| 78 | if (isFn(mdConf)) { |
| 79 | compile = mdConf(marked, renderer); |
| 80 | } else { |
| 81 | marked.setOptions( |
| 82 | merge(mdConf, { |
| 83 | renderer: merge(renderer, mdConf.renderer), |
| 84 | }) |
| 85 | ); |
| 86 | compile = marked; |
| 87 | } |
| 88 | |
| 89 | this._marked = compile; |
| 90 | this.compile = text => { |
| 91 | let isCached = true; |
| 92 | // eslint-disable-next-line no-unused-vars |
| 93 | const result = cached(_ => { |
| 94 | isCached = false; |
| 95 | let html = ''; |
| 96 | |
| 97 | if (!text) { |
| 98 | return text; |
| 99 | } |
| 100 | |
| 101 | if (isPrimitive(text)) { |
| 102 | html = compile(text); |
| 103 | } else { |
| 104 | html = compile.parser(text); |
| 105 | } |
| 106 | |
| 107 | html = config.noEmoji ? html : emojify(html, config.nativeEmoji); |
| 108 | slugify.clear(); |
| 109 | |
| 110 | return html; |
| 111 | })(text); |
| 112 | |
| 113 | const curFileName = this.router.parse().file; |
| 114 | |
| 115 | if (isCached) { |
| 116 | this.toc = this.cacheTOC[curFileName]; |
| 117 | } else { |
| 118 | this.cacheTOC[curFileName] = [...this.toc]; |
| 119 | } |
nothing calls this directly
no test coverage detected