fix: 修复 TTML ruby 注音解析死循环并支持双格式 - #130
Closed
PhantomPixel-0418 wants to merge 2 commits into
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动类型
是否包含破坏性变更
改动说明
本次 PR 为 TTML(Apple Music)歌词解析器添加 ruby 注音支持,并修复
normalizeRubyElements函数的死循环 bug。主要变更:
新增
normalizeRubyElements函数:预处理 TTML 中的tts:ruby元素,统一转换为带时间戳的<span>结构,支持两种格式:<tts:ruby base="行"><tts:ruby:textContainer><tts:ruby:text>い</tts:ruby:text></tts:ruby:textContainer></tts:ruby><span tts:ruby="container"><span tts:ruby="base">行</span><span tts:ruby="textContainer">...</span></span>修复死循环 bug:原实现中
queue.push(child)后若parentElement为 null 则continue,但 child 仍在current.children[0],导致内层循环无限重复。修复方案改为先收集子元素快照再遍历,并对已展开的 ruby 元素不再加入队列。时间戳优先级优化:当 span 包含 ruby base 子元素时,优先使用 base 的时间戳(来自
ttml:text),而非外层 span 的时间戳。新增测试用例:覆盖标准格式和简化格式的 ruby 注音解析。
关联 Issue
测试情况
pnpm test src/utils/lyric/parse.spec.ts,9 个测试全部通过<tts:ruby base="...">)<span tts:ruby="container">)截图 / 录屏
自查清单
pnpm format,并确认pnpm typecheck、pnpm lint通过pnpm build:native验证;未手写native/*/index.d.tsdev分支提交