MCPcopy
hub / github.com/showdownjs/showdown / headerId

Function headerId

src/subParsers/headers.js:58–122  ·  view source on GitHub ↗
(m)

Source from the content-addressed store, hash-verified

56 });
57
58 function headerId (m) {
59 var title,
60 prefix;
61
62 // It is separate from other options to allow combining prefix and customized
63 if (options.customizedHeaderId) {
64 var match = m.match(/\{([^{]+?)}\s*$/);
65 if (match && match[1]) {
66 m = match[1];
67 }
68 }
69
70 title = m;
71
72 // Prefix id to prevent causing inadvertent pre-existing style matches.
73 if (showdown.helper.isString(options.prefixHeaderId)) {
74 prefix = options.prefixHeaderId;
75 } else if (options.prefixHeaderId === true) {
76 prefix = 'section-';
77 } else {
78 prefix = '';
79 }
80
81 if (!options.rawPrefixHeaderId) {
82 title = prefix + title;
83 }
84
85 if (options.ghCompatibleHeaderId) {
86 title = title
87 .replace(/ /g, '-')
88 // replace previously escaped chars (&, ¨ and $)
89 .replace(/&/g, '')
90 .replace(/¨T/g, '')
91 .replace(/¨D/g, '')
92 // replace rest of the chars (&~$ are repeated as they might have been escaped)
93 // borrowed from github's redcarpet (some they should produce similar results)
94 .replace(/[&+$,\/:;=?@"#{}|^¨~\[\]`\\*)(%.!'<>]/g, '')
95 .toLowerCase();
96 } else if (options.rawHeaderId) {
97 title = title
98 .replace(/ /g, '-')
99 // replace previously escaped chars (&, ¨ and $)
100 .replace(/&amp;/g, '&')
101 .replace(/¨T/g, '¨')
102 .replace(/¨D/g, '$')
103 // replace " and '
104 .replace(/["']/g, '-')
105 .toLowerCase();
106 } else {
107 title = title
108 .replace(/[^\w]/g, '')
109 .toLowerCase();
110 }
111
112 if (options.rawPrefixHeaderId) {
113 title = prefix + title;
114 }
115

Callers 1

headers.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…