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

Function linkCompiler

src/core/render/compiler/link.js:4–64  ·  view source on GitHub ↗
({
  renderer,
  router,
  linkTarget,
  linkRel,
  compilerClass,
})

Source from the content-addressed store, hash-verified

2import { isAbsolutePath } from '../../router/util';
3
4export const linkCompiler = ({
5 renderer,
6 router,
7 linkTarget,
8 linkRel,
9 compilerClass,
10}) =>
11 (renderer.link = (href, title = '', text) => {
12 let attrs = [];
13 const { str, config } = getAndRemoveConfig(title);
14 linkTarget = config.target || linkTarget;
15 linkRel =
16 linkTarget === '_blank'
17 ? compilerClass.config.externalLinkRel || 'noopener'
18 : '';
19 title = str;
20
21 if (
22 !isAbsolutePath(href) &&
23 !compilerClass._matchNotCompileLink(href) &&
24 !config.ignore
25 ) {
26 if (href === compilerClass.config.homepage) {
27 href = 'README';
28 }
29
30 href = router.toURL(href, null, router.getCurrentPath());
31 } else {
32 if (!isAbsolutePath(href) && href.slice(0, 2) === './') {
33 href =
34 document.URL.replace(/\/(?!.*\/).*/, '/').replace('#/./', '') + href;
35 }
36 attrs.push(href.indexOf('mailto:') === 0 ? '' : `target="${linkTarget}"`);
37 attrs.push(
38 href.indexOf('mailto:') === 0
39 ? ''
40 : linkRel !== ''
41 ? ` rel="${linkRel}"`
42 : ''
43 );
44 }
45
46 if (config.disabled) {
47 attrs.push('disabled');
48 href = 'javascript:void(0)';
49 }
50
51 if (config.class) {
52 attrs.push(`class="${config.class}"`);
53 }
54
55 if (config.id) {
56 attrs.push(`id="${config.id}"`);
57 }
58
59 if (title) {
60 attrs.push(`title="${title}"`);
61 }

Callers 1

_initRendererMethod · 0.90

Calls 4

getAndRemoveConfigFunction · 0.90
_matchNotCompileLinkMethod · 0.80
toURLMethod · 0.45
getCurrentPathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…