mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-25 16:28:04 +08:00
added a function to convert html to text
This commit is contained in:
parent
af0abff2b4
commit
c34b56bc50
2 changed files with 7 additions and 1 deletions
|
|
@ -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, "");
|
||||
|
|
|
|||
|
|
@ -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 || "";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue