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

feat(TTML): Add support to tts:ruby #5645

Merged
merged 1 commit into from
Sep 12, 2023
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
11 changes: 11 additions & 0 deletions lib/text/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,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
Original file line number Diff line number Diff line change
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