From 2df34d6068ff0ef6b007653a46801a01f23381d5 Mon Sep 17 00:00:00 2001 From: birme Date: Wed, 2 Nov 2016 15:22:14 +0100 Subject: [PATCH 1/2] TTML subtitles: Support for
inside a paragraph --- lib/media/ttml_text_parser.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/media/ttml_text_parser.js b/lib/media/ttml_text_parser.js index b7e8ac2455..bf1070d376 100644 --- a/lib/media/ttml_text_parser.js +++ b/lib/media/ttml_text_parser.js @@ -168,6 +168,15 @@ shaka.media.TtmlTextParser.getLeafNodes_ = function(element) { return result; var childNodes = element.childNodes; + if (element.nodeName == 'p') { + // Replace
inside a

paragraph with a newline character. + // The
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 From f4514ba8f2d69350788a5fb9073bbf7e1db99d66 Mon Sep 17 00:00:00 2001 From: birme Date: Wed, 2 Nov 2016 20:47:55 +0100 Subject: [PATCH 2/2] Added unit test for br element inside a paragraph in TTML subtitle --- test/media/ttml_text_parser_unit.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/media/ttml_text_parser_unit.js b/test/media/ttml_text_parser_unit.js index 914a047379..c399bbed01 100644 --- a/test/media/ttml_text_parser_unit.js +++ b/test/media/ttml_text_parser_unit.js @@ -390,6 +390,14 @@ describe('TtmlTextParser', function() { ''); }); + it('inserts a newline on br in a p block', function() { + verifyHelper( + [ + {start: 62.05, end: 3723.2, text: 'Line1\nLine2'} + ], + '

Line1
Line2

'); + }); /** * @param {!Array} cues