fix: remove html tags
This commit is contained in:
5492
package-lock.json
generated
Normal file
5492
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -40,6 +40,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.17.1",
|
"axios": "^0.17.1",
|
||||||
"he": "^1.1.1",
|
"he": "^1.1.1",
|
||||||
"lodash": "^4.17.4"
|
"lodash": "^4.17.4",
|
||||||
|
"striptags": "^3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import he from 'he';
|
import he from 'he';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { find } from 'lodash';
|
import { find } from 'lodash';
|
||||||
|
import striptags from 'striptags';
|
||||||
|
|
||||||
export async function getSubtitles({
|
export async function getSubtitles({
|
||||||
videoID,
|
videoID,
|
||||||
@@ -46,14 +47,14 @@ export async function getSubtitles({
|
|||||||
const [, start] = startRegex.exec(line);
|
const [, start] = startRegex.exec(line);
|
||||||
const [, dur] = durRegex.exec(line);
|
const [, dur] = durRegex.exec(line);
|
||||||
|
|
||||||
const fontTag = new RegExp('<'+'font'+'[^><]*>|<.'+'font'+'[^><]*>','g');
|
|
||||||
const htmlText = line
|
const htmlText = line
|
||||||
.replace(/<text.+>/, '')
|
.replace(/<text.+>/, '')
|
||||||
.replace(/&/gi, '&')
|
.replace(/&/gi, '&')
|
||||||
.replace(/<\/?[^>]+(>|$)/g, '')
|
.replace(/<\/?[^>]+(>|$)/g, '');
|
||||||
.replace(fontTag, '');
|
|
||||||
|
|
||||||
const text = he.decode(htmlText);
|
const strippedText = striptags(htmlText);
|
||||||
|
|
||||||
|
const text = he.decode(strippedText);
|
||||||
|
|
||||||
return { start, dur, text };
|
return { start, dur, text };
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user