diff --git a/src/js/subtitle.js b/src/js/subtitle.js index 8d075ba..32c2fc4 100644 --- a/src/js/subtitle.js +++ b/src/js/subtitle.js @@ -18,14 +18,12 @@ class Subtitle { track.oncuechange = () => { const cue = track.activeCues[0]; + this.container.innerHTML = ''; if (cue) { - this.container.innerHTML = ''; - const p = document.createElement('p'); - p.appendChild(cue.getCueAsHTML()); - this.container.appendChild(p); - } - else { - this.container.innerHTML = ''; + const template = document.createElement('div'); + template.appendChild(cue.getCueAsHTML()); + const trackHtml = template.innerHTML.split(/\r?\n/).map(item => `
${item}
`).join(''); + this.container.innerHTML = trackHtml; } this.events.trigger('subtitle_change'); }; @@ -52,4 +50,4 @@ class Subtitle { } } -export default Subtitle; \ No newline at end of file +export default Subtitle;