Fix broken Markdown headings with quotes

This commit is contained in:
Andrey Lomakin 2021-02-02 10:45:21 +03:00
parent 755a9095f5
commit d66a05cf57
No known key found for this signature in database
GPG Key ID: B53984915604FD65
2 changed files with 14 additions and 5 deletions

View File

@ -46,7 +46,7 @@ export class MenuStore {
if (!id) {
return;
}
scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${id}"]`);
scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(id)}"]`);
}
/**
@ -152,7 +152,7 @@ export class MenuStore {
item = this.flatItems.find(i => SECURITY_SCHEMES_SECTION_PREFIX.startsWith(i.id));
this.activate(item);
}
this.scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${id}"]`);
this.scroll.scrollIntoViewBySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(id)}"]`);
}
};
@ -162,7 +162,7 @@ export class MenuStore {
*/
getElementAt(idx: number): Element | null {
const item = this.flatItems[idx];
return (item && querySelector(`[${SECTION_ATTR}="${item.id}"]`)) || null;
return (item && querySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(item.id)}"]`)) || null;
}
/**
@ -174,7 +174,7 @@ export class MenuStore {
if (item && item.type === 'group') {
item = item.items[0];
}
return (item && querySelector(`[${SECTION_ATTR}="${item.id}"]`)) || null;
return (item && querySelector(`[${SECTION_ATTR}="${MenuStore.escapeQuotes(item.id)}"]`)) || null;
}
/**
@ -274,4 +274,12 @@ export class MenuStore {
this._unsubscribe();
this._hashUnsubscribe();
}
private static escapeQuotes(str: string) : string {
if (typeof str != 'undefined') {
str = str.replace(/["\\]/g, '\\$&');
}
return str;
}
}

View File

@ -198,5 +198,6 @@ function parseURL(url: string) {
export function unescapeHTMLChars(str: string): string {
return str
.replace(/&#(\d+);/g, (_m, code) => String.fromCharCode(parseInt(code, 10)))
.replace(/&/g, '&');
.replace(/&/g, '&')
.replace(/"/g, '"');
}