Repository navigation
refactor(dom): 预重构 —— 把 pre 切块的切分内核抽成与形状无关的模块,pre 成为它的一个配置(#705) - #722
Merged
Merged
Conversation
切块内核(src/dom/chunk-split.ts)负责 token 化后的行聚合、超长块不包装、 按原顺序重建、打切分标记与幂等、已翻译结果内不切,以及还原;里面不含 任何 pre 专属判断。容器的形状只在两处不同,以配置给出:换行从哪儿来 (tokenize)、行怎么聚成块(group)。 pre 成为内核的一个配置:换行来自文本里的 '\n',按空行聚块;装饰行、 列表条目行独立成块、代码块与含块级子元素不切这些规则原样保留在 pre-split 里。行为逐字节不变。 还原函数 unsplitPre 改名 unsplitChunks、移进内核,并修正文档注释:它搬回 的是切块里的所有子节点(文本节点与原样移入的行内节点),不只文本节点。 调用方(还原流程、单元测试的导入、测试文档与桩生成器的映射)跟着改名。 Co-Authored-By: zhexuancai-uts <261878103+zhexuancai-uts@users.noreply.github.com>
Co-Authored-By: zhexuancai-uts <261878103+zhexuancai-uts@users.noreply.github.com>
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.
问题
#694 要给以 br 分行的超长段落做切块,需要的流程和 pre 切块(#65)几乎一样:子节点 token 化,聚合成行,包进切块,给容器打标记,还原时拆回去。但这套流程写死在 pre 上,没法直接复用。
根因
token 化、行聚合、重建、打标记和还原都写在
splitPre/unsplitPre里,和 pre 专属的判断混在一起。按 br 切行与 pre 切块只差两处:换行来自哪里,行怎么聚成块。修复
src/dom/chunk-split.ts,不认任何具体标签。 对外提供两件事:splitIntoChunks(container, shape):unsplitChunks(container):拆回切块,移除标记。tokenize决定换行从哪儿来,group决定行怎么聚成块。\n,按空行聚块。下面这些规则原样留在pre-split.ts:unsplitPre改为形状中立的unsplitChunks,移进内核。文档注释改正为“搬回切块里的所有子节点(文本节点与原样移入的行内节点)”,原注释写的是只搬文本节点,不对。splitPres改为splitContainers)、单元测试的导入、DEEP-TESTING.md与桩生成器的映射。验证
pnpm test: 115 个文件、1427 条,全部通过。pre 切块、超长 README、观察器的切块二次收集都在其中。pnpm typecheck通过。pnpm test:e2e:core: 98 条通过,2 条跳过。纯文本 pre 切块翻译与还原的端到端用例都在其中。Closes #705