Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4aacd093e5 | |||
| aab478359b |
@@ -5,6 +5,17 @@ function escapeHtmlAttr(s: string): string {
|
|||||||
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode HTML entities that marked introduces before we re-escape for our own output.
|
||||||
|
// Order matters: & must be last to avoid double-decoding.
|
||||||
|
function decodeHtmlEntities(s: string): string {
|
||||||
|
return s
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, "'")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/&/g, "&");
|
||||||
|
}
|
||||||
|
|
||||||
export function extractTags(body: string): string[] {
|
export function extractTags(body: string): string[] {
|
||||||
const cleaned = body.replace(CODE_FENCE_RE, "");
|
const cleaned = body.replace(CODE_FENCE_RE, "");
|
||||||
const tags = new Set<string>();
|
const tags = new Set<string>();
|
||||||
@@ -39,8 +50,8 @@ export function linkifyWikilinks(html: string): string {
|
|||||||
.map((part, i) => {
|
.map((part, i) => {
|
||||||
if (i % 2 === 1) return part;
|
if (i % 2 === 1) return part;
|
||||||
return part.replace(WIKILINK_RE, (_full, title: string, display?: string) => {
|
return part.replace(WIKILINK_RE, (_full, title: string, display?: string) => {
|
||||||
const trimmed = title.trim();
|
const trimmed = decodeHtmlEntities(title.trim());
|
||||||
const label = display || trimmed;
|
const label = display ? decodeHtmlEntities(display) : trimmed;
|
||||||
const encoded = encodeURIComponent(trimmed);
|
const encoded = encodeURIComponent(trimmed);
|
||||||
return `<a class="wikilink" data-title="${escapeHtmlAttr(trimmed)}" href="/notes/by-title?title=${encoded}">${escapeHtmlAttr(label)}</a>`;
|
return `<a class="wikilink" data-title="${escapeHtmlAttr(trimmed)}" href="/notes/by-title?title=${encoded}">${escapeHtmlAttr(label)}</a>`;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user