Skip to content

Commit

Permalink
TTML subtitles: Support for <br> inside a paragraph (#572)
Browse files Browse the repository at this point in the history
Replace <br> inside a paragraph with newlines.
  • Loading branch information
birme authored and joeyparrish committed Nov 29, 2016
1 parent a02e903 commit 45291da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/media/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ shaka.media.TtmlTextParser.getLeafNodes_ = function(element) {
return result;

var childNodes = element.childNodes;
if (element.nodeName == 'p') {
// Replace <br> inside a <p> paragraph with a newline character.
// The <br> node is later on skipped
for (var j = 0; j < childNodes.length; j++) {
if (childNodes[j].nodeName == 'br' && j > 0) {
childNodes[j - 1].textContent += '\n';
}
}
}
for (var i = 0; i < childNodes.length; i++) {
// Currently we don't support styles applicable to span
// elements, so they are ignored
Expand Down
8 changes: 8 additions & 0 deletions test/media/ttml_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ describe('TtmlTextParser', function() {
'</tt>');
});

it('inserts a newline on br in a p block', function() {
verifyHelper(
[
{start: 62.05, end: 3723.2, text: 'Line1\nLine2'}
],
'<tt><body><p begin="01:02.05" ' +
'end="01:02:03.200">Line1<br/>Line2</p></body></tt>');
});

/**
* @param {!Array} cues
Expand Down

0 comments on commit 45291da

Please sign in to comment.