Skip to content

Commit

Permalink
feat(TTML): Add support to tts:ruby (#5645)
Browse files Browse the repository at this point in the history
Related to #2853
  • Loading branch information
avelad committed Sep 12, 2023
1 parent 3a4f108 commit 9fd220e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/text/ttml_text_parser.js
Expand Up @@ -724,6 +724,17 @@ shaka.text.TtmlTextParser = class {
if (textDecorationElement) {
TtmlTextParser.addTextDecoration_(cue, textDecorationElement);
}

const ruby = TtmlTextParser.getStyleAttribute_(
cueElement, region, styles, 'ruby', shouldInheritRegionStyles);
switch (ruby) {
case 'container':
cue.rubyTag = 'ruby';
break;
case 'text':
cue.rubyTag = 'rt';
break;
}
}

/**
Expand Down
27 changes: 27 additions & 0 deletions test/text/ttml_text_parser_unit.js
Expand Up @@ -1286,6 +1286,33 @@ describe('TtmlTextParser', () => {
{startTime: 62.05, endTime: 3723.2});
});

it('supports tts:ruby', () => {
verifyHelper(
[{
startTime: 62.05,
endTime: 3723.2,
payload: '',
nestedCues: [{
startTime: 62.05,
endTime: 3723.2,
payload: 'Line1',
}, {
startTime: 62.05,
endTime: 3723.2,
payload: 'Line2',
rubyTag: 'rt',
}],
rubyTag: 'ruby',
}],
// With anonymous spans
'<tt xmlns:tts="http://www.w3.org/ns/ttml#styling"><body><div>' +
'<p begin="01:02.05" end="01:02:03.200" tts:ruby="container">' +
'<span tts:ruby="base">Line1</span><span tts:ruby="text">Line2' +
'</span></p></div></body></tt>',
{periodStart: 0, segmentStart: 60, segmentEnd: 3730, vttOffset: 0},
{startTime: 62.05, endTime: 3723.2});
});

it('inserts line breaks for <br> tags', () => {
verifyHelper(
[{
Expand Down

0 comments on commit 9fd220e

Please sign in to comment.