Skip to content

Commit

Permalink
fix(Text#toHTML): Return empty string if the text is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Dec 31, 2024
1 parent f76a8e5 commit f3c777b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parser/classes/ContentMetadataView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AvatarStackView from './AvatarStackView.js';

export type MetadataRow = {
metadata_parts?: {
text: Text;
text: Text | null;
avatar_stack: AvatarStackView | null;
}[];
};
Expand All @@ -21,7 +21,7 @@ export default class ContentMetadataView extends YTNode {
super();
this.metadata_rows = data.metadataRows.map((row: RawNode) => ({
metadata_parts: row.metadataParts?.map((part: RawNode) => ({
text: Text.fromAttributed(part.text || {}),
text: part.text ? Text.fromAttributed(part.text) : null,
avatar_stack: Parser.parseItem(part.avatarStack, AvatarStackView)
}))
}));
Expand Down
3 changes: 3 additions & 0 deletions src/parser/classes/misc/TextRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default class TextRun implements Run {
if (this.italics) tags.push('i');
if (this.strikethrough) tags.push('s');
if (this.deemphasize) tags.push('small');

if (!this.text?.length)
return '';

const escaped_text = escape(this.text);
const styled_text = tags.map((tag) => `<${tag}>`).join('') + escaped_text + tags.map((tag) => `</${tag}>`).join('');
Expand Down

0 comments on commit f3c777b

Please sign in to comment.