Skip to content

Commit

Permalink
fix(text): Allow comments in the TTML parser (shaka-project#3827)
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván authored Jan 4, 2022
1 parent 73b4302 commit c5a81f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/text/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ shaka.text.TtmlTextParser = class {
/** @type {Element} */
let parentElement = /** @type {Element} */(cueNode.parentNode);

if (cueNode.nodeType == Node.COMMENT_NODE) {
// The comments do not contain information that interests us here.
return null;
}

if (cueNode.nodeType == Node.TEXT_NODE) {
// This should generate an "anonymous span" according to the TTML spec.
// So pretend the element was a <span>. parentElement was set above, so
Expand Down
9 changes: 9 additions & 0 deletions test/text/ttml_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ describe('TtmlTextParser', () => {
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

it('supports comments in the body', () => {
verifyHelper(
[],
'<tt><body><div>' +
'<!-- text-based TTML -->' +
'</div></body></tt>',
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

it('parses alignment from textAlign attribute of a region', () => {
verifyHelper(
[
Expand Down

0 comments on commit c5a81f5

Please sign in to comment.