Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTML subtitles: Support for <br> inside a paragraph #572

Merged
merged 2 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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