@@ -193,15 +193,6 @@ shaka.media.TtmlTextParser.getLeafNodes_ = function(element) {
193193 return result ;
194194
195195 var childNodes = element . childNodes ;
196- if ( element . nodeName == 'p' ) {
197- // Replace <br> inside a <p> paragraph with a newline character.
198- // The <br> node is later on skipped
199- for ( var j = 0 ; j < childNodes . length ; j ++ ) {
200- if ( childNodes [ j ] . nodeName == 'br' && j > 0 ) {
201- childNodes [ j - 1 ] . textContent += '\n' ;
202- }
203- }
204- }
205196 for ( var i = 0 ; i < childNodes . length ; i ++ ) {
206197 // Currently we don't support styles applicable to span
207198 // elements, so they are ignored
@@ -228,6 +219,25 @@ shaka.media.TtmlTextParser.getLeafNodes_ = function(element) {
228219} ;
229220
230221
222+ /**
223+ * Insert \n where <br> tags are found
224+ *
225+ * @param {!Node } element
226+ * @private
227+ */
228+ shaka . media . TtmlTextParser . addNewLines_ = function ( element ) {
229+ var childNodes = element . childNodes ;
230+
231+ for ( var i = 0 ; i < childNodes . length ; i ++ ) {
232+ if ( childNodes [ i ] . nodeName == 'br' && i > 0 ) {
233+ childNodes [ i - 1 ] . textContent += '\n' ;
234+ } else if ( childNodes [ i ] . childNodes . length > 0 ) {
235+ shaka . media . TtmlTextParser . addNewLines_ ( childNodes [ i ] ) ;
236+ }
237+ }
238+ } ;
239+
240+
231241/**
232242 * Parses an Element into a TextTrackCue or VTTCue.
233243 *
@@ -251,6 +261,8 @@ shaka.media.TtmlTextParser.parseCue_ = function(
251261 cueElement . textContent == '' )
252262 return null ;
253263
264+ shaka . media . TtmlTextParser . addNewLines_ ( cueElement ) ;
265+
254266 // Get time
255267 var start = shaka . media . TtmlTextParser . parseTime_ (
256268 cueElement . getAttribute ( 'begin' ) , rateInfo ) ;
0 commit comments