Use underscore to escape XML

This commit is contained in:
Jackson Harper 2022-08-29 22:26:06 +08:00
parent 48e6d63158
commit 8bc950ba87
2 changed files with 5 additions and 2 deletions

View file

@ -21,6 +21,7 @@
},
"devDependencies": {
"@types/node": "^14.11.2",
"@types/underscore": "^1.11.4",
"eslint-plugin-prettier": "^4.0.0"
},
"dependencies": {
@ -31,6 +32,7 @@
"dotenv": "^16.0.1",
"jsonwebtoken": "^8.5.1",
"linkedom": "^0.14.12",
"microsoft-cognitiveservices-speech-sdk": "^1.22.0"
"microsoft-cognitiveservices-speech-sdk": "^1.22.0",
"underscore": "^1.13.4"
}
}

View file

@ -1,4 +1,5 @@
import { parseHTML } from 'linkedom'
import * as _ from 'underscore'
// this code needs to be kept in sync with the
// frontend code in: useReadingProgressAnchor
@ -59,7 +60,7 @@ function emit(textItems: string[], text: string) {
}
function cleanTextNode(textNode: ChildNode): string {
return (textNode.textContent ?? '').replace(/\s+/g, ' ')
return _.escape(textNode.textContent ?? ''.replace(/\s+/g, ' '))
}
function emitTextNode(