Skip to content

Parse IMSC1 TTML whose elements carry a namespace prefix - #8192

Open
SwastikTripathi wants to merge 1 commit into
video-dev:masterfrom
SwastikTripathi:fix/imsc1-prefixed-ttml
Open

SwastikTripathi wants to merge 1 commit into
video-dev:masterfrom
SwastikTripathi:fix/imsc1-prefixed-ttml

Conversation

@SwastikTripathi

Copy link
Copy Markdown

This PR will...

Find the TTML elements of an IMSC1 sample by local name, so documents that put their elements under a prefix are parsed:

<tt:tt xmlns:tt="http://www.w3.org/ns/ttml" xml:lang="en"><tt:body><tt:div><tt:p begin="00:00:01.000" end="00:00:03.000">Hello</tt:p></tt:div></tt:body></tt:tt>

Why is this Pull Request needed?

parseTTML looked up the root with getElementsByTagName('tt'), which compares the qualified name. For <tt:tt> (the form EBU-TT-D uses) it finds nothing, so the whole sample fails with "Invalid ttml" and no subtitles show. styling, layout and body were looked up the same way, and a line break was detected with nodeName === 'br', which is tt:br there.

The lookups now use getElementsByTagNameNS('*', name), which matches the local name in any namespace or none, and the line break check uses localName. Documents with a default namespace, or with no namespace at all, are found exactly as before. The style, region and [begin] lookups go through querySelectorAll, whose type selectors already match the local name, so they didn't need a change.

Are there any points in the code the reviewer needs to double check?

This keeps the current lenient handling of documents without the TTML namespace, which #8067 discusses changing. If that lands, getElementsByLocalName is the one place to switch to the TTML namespace.

Resolves issues:

Fixes #8148

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

Three new unit tests (a prefixed document, prefixed styles and regions, a prefixed <tt:br/>) fail before the change and pass after. npm run test:unit passes (1286 tests in headless Chrome), plus eslint, prettier and npm run type-check.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IMSC1: TTML documents that use a namespace prefix (<tt:tt>, as in EBU-TT-D) fail with "Invalid ttml"

1 participant