mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 04:21:35 +00:00
feat(parser): Text#toHTML (#300)
Added support to render Text nodes as HTML for use in web applications.
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
import TextRun from './TextRun';
|
||||
import EmojiRun from './EmojiRun';
|
||||
|
||||
export interface Run {
|
||||
text: string;
|
||||
toString(): string;
|
||||
toHTML(): string;
|
||||
}
|
||||
|
||||
export function escape(text: string) {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
class Text {
|
||||
text: string;
|
||||
runs;
|
||||
@@ -17,6 +32,10 @@ class Text {
|
||||
}
|
||||
}
|
||||
|
||||
toHTML() {
|
||||
return this.runs ? this.runs.map((run) => run.toHTML()).join('') : this.text;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user