added a function to convert html to text

This commit is contained in:
Miodec 2022-11-15 13:01:19 +01:00
parent af0abff2b4
commit c34b56bc50
2 changed files with 7 additions and 1 deletions

View file

@ -105,7 +105,7 @@ export async function getSection(language: string): Promise<Section> {
sectionText = sectionText.replace(/<\/p><p>+/g, " ");
// Convert HTML to text
sectionText = $("<div/>").html(sectionText).text();
sectionText = Misc.htmlToText(sectionText);
// Remove reference links
sectionText = sectionText.replace(/\[\d+\]/gi, "");

View file

@ -1300,3 +1300,9 @@ export function areUnsortedArraysEqual(a: unknown[], b: unknown[]): boolean {
export function areSortedArraysEqual(a: unknown[], b: unknown[]): boolean {
return a.length === b.length && a.every((v, i) => v === b[i]);
}
export function htmlToText(html: string): string {
const el = document.createElement("div");
el.innerHTML = html;
return el.textContent || el.innerText || "";
}