Skip to content

fix: preserve PDF list numbering, signature underscores, and Buffer input safety - #220

Merged
Vantalens merged 2 commits into
mainfrom
fix/pdf-list-numbering-buffer
Sep 24, 2026
Merged

Vantalens merged 2 commits into
mainfrom
fix/pdf-list-numbering-buffer

Conversation

@Vantalens

Copy link
Copy Markdown
Owner

变更说明

修复 PDF 转换链路的三个问题(延续 #216 的 PDF 可靠性主题):

  1. 2 倍行距的条款列表被原 1.6 倍行高阈值拆成单条 list,writer 将每项都从 1 重新编号;
  2. PDF 签名线等纯下划线串被 markdown 下划线强调正则回溯逐轮缩减(12→8→6),污染 txt/json/csv/xlsx/pptx 输出;
  3. Node Buffer 直接传入 PDF.js 时,其底层共享内存池被 transfer 整块 detach,污染无关数据。

变更内容

  • public/formats/pdf.js
    • coercePdfBytes:Node Buffer 先复制为独立 Uint8Array 再交给 PDF.js,避免 transfer 共享内存池导致无关数据被 detach。
    • analyzeSingleColumnLayout:新增 lastLineWasListItem 状态;列表合并条件改为 paragraphTextBuffer.length === 0 && lastBlock?.type === "list" && lastBlock.ordered === ordered && (!isNewBlock || (lastLineWasListItem && yGap <= lastHeight * 3.0))——同类列表项行距阈值由 1.6 倍放宽到 3 倍行高且要求上一行为列表项,段落打断后不再合并。
  • public/formats/text-utils.js:stripMarkdownInlineSyntax 的两条下划线强调正则增加 (?!_) / (?<!_) 守卫,纯下划线串(如 PDF 签名线 Date: ____________)不再被缩减;真实 __强调__ 标记仍正常剥离。
  • scripts/layout-offset-regression-test.js:新增断言——2 倍行距列表合并为单块 4 项、>3 倍行距不合并、段落打断列表、下划线串 round-trip 保留、真强调标记仍剥离。
  • scripts/pdf-reader-test.js:新增测试 13(Buffer 输入经 expandPdfContentForTextExtraction 后共享池哨兵与输入字节均存活;带 pdfjsAvailable 守卫,缺 pdfjs 环境跳过)。
  • CHANGELOG.md、docs/development/DEVELOPMENT_TASKS.md:补充本次修复记录。

测试验证

  • 本地完整 npm test(50 个脚本)双向验证全绿:含 pdfjs-dist 环境与隐藏 pdfjs-dist 环境(缺 pdfjs 时相关用例跳过而非失败)均通过。
  • 仿真中英混排 PDF 全链路实测 20/20:条款编号恢复 1/2/3/4、签名下划线 12 个保留、pdf→pdf 字节一致(scripts/lib/validate-mixed-pdf.mjs,本地验证脚本,未入库)。
  • node --check 四个改动脚本语法通过;git diff --check 无空白问题。

相关 Issue

Refs #216

注意事项

  • 工作区另有未提交的 landing 页样式与 dev 脚本改动(package.json、public/landing-view.js、public/styles.css、public/styles/landing.css),属并行工作,未包含在本 PR。

- Redesign README: centered header, logo, badges, landing/workbench
  screenshots, emoji section markers, star CTA
- Fix 14 broken links: i18n READMEs under docs/i18n/, relocated docs
  (CONVERSION_PATHS, SECURITY_POLICY, CONVERSION_ROUTING, INSTALL,
  PP_OCRV5_BROWSER_VERIFICATION), schema JSON replaces deleted md
- Add docs/assets/: generated logo + fresh 2160x1350 app screenshots
- Archive 4 internal process reports to docs/development/
- .gitignore: ignore .tmp-* scratch files
…nput safety

- PDF 版面分析:同类列表项行距放宽到 3 倍行高合并(原 1.6 倍阈值会把 2 倍行距的
  条款列表拆成单条 list,writer 将每项都从 1 重新编号)
- markdown 剥离不再吞纯下划线串:PDF 签名线 "Date: ____________" 此前被正则
  回溯逐轮缩减(12→8→6),影响 txt/json/csv/xlsx/pptx 输出
- PDF.js 提取前将 Node Buffer 复制为独立 Uint8Array,避免 transfer 共享内存池
  导致无关数据被 detach
- 回归测试:layout-offset 增加列表合并/打断/下划线断言;pdf-reader 增加 Buffer
  输入池安全测试(含 pdfjs 缺失环境守卫)

Refs #216
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@Vantalens
Vantalens merged commit e499e1d into main Sep 24, 2026
8 checks passed
@Vantalens
Vantalens deleted the fix/pdf-list-numbering-buffer branch September 24, 2026 07:26
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.

1 participant