refactoring van de cmap structuren bijna compleet
This commit is contained in:
@@ -182,6 +182,34 @@ function positionIsProtected(start, end, ranges) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Prefix every unprotected CamelCase WikiWord with the literal escape marker. */
|
||||
function protectCamelCaseWikiWords(markdown) {
|
||||
const wikiWordPattern = /(?<![!\p{L}\p{N}._-])((?:\p{Lu}\p{Ll}+){2,})(?![\p{L}\p{N}_-])/gu;
|
||||
let fence = null;
|
||||
return String(markdown || "").split("\n").map((line) => {
|
||||
const fenceMatch = line.match(/^\s*(```+|~~~+)/);
|
||||
if (fenceMatch) {
|
||||
const marker = fenceMatch[1].charAt(0);
|
||||
fence = fence === null ? marker : (fence === marker ? null : fence);
|
||||
return line;
|
||||
}
|
||||
if (fence !== null || /^\s{4}/.test(line)) return line;
|
||||
|
||||
const ranges = markdownProtectedRanges(line);
|
||||
const matches = Array.from(line.matchAll(wikiWordPattern));
|
||||
let result = line;
|
||||
for (let index = matches.length - 1; index >= 0; index -= 1) {
|
||||
const match = matches[index];
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
if (!positionIsProtected(start, end, ranges)) {
|
||||
result = result.slice(0, start) + `!${match[0]}` + result.slice(end);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}).join("\n");
|
||||
}
|
||||
|
||||
/** Encode the initial WikiWord letter so a later render pass cannot link it. */
|
||||
function literalWikiWord(namespace, wikiWord) {
|
||||
const characters = Array.from(wikiWord);
|
||||
@@ -335,6 +363,7 @@ export {
|
||||
expandNamespacedMarkdownLinks,
|
||||
expandTodoMarkup,
|
||||
expandWikiMentions,
|
||||
protectCamelCaseWikiWords,
|
||||
extractCmapEmbeds,
|
||||
restoreCmapEmbeds
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user