Skip to content

fix(html2md): preserve media resources and readable controls - #1334

Open
lanyue-llk wants to merge 4 commits into
mainfrom
codex/content-media-forms
Open

lanyue-llk wants to merge 4 commits into
mainfrom
codex/content-media-forms

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

问题与方案

页面里可读的信息不只来自文本节点。旧转换会丢掉表单值、图片的文字替代、嵌入媒体地址和空控件标签;响应式图片和懒加载占位图也可能导出错误资源。

本 PR 从 #919 拆出这组转换规则:按标准资源声明选择图片,懒加载属性只作后备;保留可读表单值和选项边界,排除密码、隐藏输入和文件输入;图片无法引用时保留替代文字。媒体链接和普通链接采用同一 URL 安全规则,标签仍按普通文字转义。

根因、方案与验收

问题 根因 方案依据 泛化验收
图片资源或替代文字丢失 只看 src;把缺少地址等同于没有可读内容 标准 srcset、有效 src 优先,私有懒加载声明仅作后备;无资源时保留 alt 普通及响应式图片、无效候选、逗号与 data URL、懒加载占位、图片作为链接唯一标签
媒体引用不一致 图片、音视频和普通链接各自判断地址 使用共享资源选择与安全规则 source、poster、相对地址、危险协议与空地址;保持可读标签
控件文字黏连或敏感值泄露 选项、按钮和时间标签缺少边界;直接抄录所有输入值 保留可读表单表示,明确排除敏感值和不应导出的输入类型 选项与组标签、checkbox/radio 状态、密码、隐藏和文件输入、空控件标签

本组处理转换器所收到的 DOM 值。浏览器当前值覆盖初始属性的采样属于 #1337;两者通过同一转换接口衔接。

修复机制图

标准资源优先,私有懒加载声明仅作后备

flowchart LR
  A[DOM 资源声明与控件状态] --> B{有可用标准声明?}
  B -->|有| C[保留标准资源]
  B -->|无| D[检查懒加载后备声明]
  C --> E[导出资源链接与可读标签]
  D --> E
  F[表单值与选项] --> G[排除敏感值并保留文字边界]
  G --> E
Loading

范围与依赖

基于 main 的 99c24fd8debf6e6cb51c30b22080c5cd673ae85e,可独立验证。本组修改 moli-html2md 的共享资源、表单和可读标签转换,并同步原生 DOM 验收。HTTP 测试只固定响应元数据,排除跨秒请求造成的无关差异。运行时当前值、CSS 可见性和页面资源地址解析属于后续的页面适配 PR。复杂表格中的相同内容由后续表格 PR 复用这些规则。

验证

  • 原生 DOM 导出专项:22 个场景通过。

  • cargo fmt --all

  • cargo test -p moli-html2md --locked:全部通过。

  • cargo clippy -p moli-html2md --all-targets --locked -- -D warnings:通过。

  • 红绿验证:图片作为邮件链接唯一标签时,旧转换丢失 Email,本修改保留标签。测试还覆盖响应式资源、无效候选、懒加载占位图、危险 URL、表单敏感值与文本边界。

完整仓库测试交由 CI。测试检查实际导出内容及 Markdown 渲染语义,不要求表格采用特定表示格式。

分支验证与集成验证

此前的 PR 集成 CI 对应提交 d9695fe6870e4f191a0906c187ca391c2797d101。main 的 gamepad 和 credential 测试曾引用已移除的 context 字段,分别由 #1343 与 #1351 修复并合入;当前集成快照已包含两项修复。

与 #1305 的关系

#1305 直接基于 main,负责执行调用者明确指定的脚本,等待 Promise 和导航后走标准导出路径。这四组修复负责导出内容的完整性与语义。双方没有代码前置依赖;组合后,交互后的 DOM 会使用这些共享转换规则。

默认只读采集和明确交互采集是不同的测量协议。报告中的历史成绩仍绑定原调用协议;不能给单一方法补交互后替换同一行成绩。

报告

完整 WebMainBench 报告 保留 #919 已发布的完整运行及方法对比。该运行对应 721bd2e329f96c06573db6e6b257a149cf17a6fe,不代表本拆分分支的新测量。

完整测试的两个验收边界

原生 DOM 的图片替代文字验收随本组修改,覆盖无资源、空资源、邮件链接、空标签和字面 Markdown。后续格式组单独更新属性换行验收,避免把一个 PR 的必要测试留到后面的 PR。

HTTP 输出格式测试对同一响应逐字节比较。测试服务固定 Date,并让 JSON 的两次请求跨越一秒,验证结果不受自动响应日期影响;产品响应头和完整输出断言保持原样。

HTTP 日期场景已完成红绿验证:未固定日期时,跨秒的 JSON 完整输出比较失败;固定日期后通过。完整输出比较未放宽。

PR stack

GitHub 原生依赖链:#1334 → #1335 → #1336 → #1337 → #1380 → #1428 → #1431 → #1432。

每个 PR 的 GitHub base 都是左侧紧邻分支,因此 Files changed 只显示本层增量。按从左到右的顺序合入。#919 是保留的历史完整组合,不是这条链的依赖;#1429 独立面向 main,只提供通用 CI 评测入口。

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Sequential Navigation Soak A/B

✅ HEAD completed the 200-navigation resilience and memory observation.

One browser process, one target, and one CDP session navigate CSDN → SegmentFault → Huaban → example.com repeatedly. This run issued 200 Page.navigate commands per binary.

Common ancestor d9928760ed → HEAD 7c4e732346; benchmark order: base-first; workflow: success.

Session resilience

Metric Base HEAD
Attempted / planned 200 / 200 200 / 200
Direct observable pass 198 / 200 198 / 200
Failures / recovered 2 / 2 2 / 2
Recovery failures 0 0
Lifecycle order violations 0 0
Network order violations 0 0
Wall time 534.4 s 520.9 s

A public-page failure is reported separately from an unrecoverable session. The soak requires all navigation attempts, zero failed recovery, zero lifecycle/network ordering violations, and complete resource evidence.

Process-tree memory

Metric Base HEAD Δ
Boundary samples 200 200 0
Boundary RSS samples 200 200 0
Boundary PSS samples 200 200 0
Periodic peak RSS 275.6 MiB 266.2 MiB -9.4 MiB
Periodic peak PSS 271.6 MiB 264.2 MiB -7.4 MiB
RSS · first 10 avg 182.7 MiB 178.7 MiB -3.9 MiB
RSS · last 10 avg 170.3 MiB 188.8 MiB +18.6 MiB
RSS · last − first window -12.4 MiB +10.1 MiB +22.5 MiB
RSS · warm slope / 100 nav +0.3 MiB +0.9 MiB +0.6 MiB
PSS · first 10 avg 178.7 MiB 176.1 MiB -2.6 MiB
PSS · last 10 avg 167.6 MiB 185.7 MiB +18.1 MiB
PSS · last − first window -11.1 MiB +9.7 MiB +20.8 MiB
PSS · warm slope / 100 nav +0.7 MiB +0.9 MiB +0.2 MiB
Peak file descriptors 59 60 1
Peak threads 31 29 -2

HEAD memory by 50-navigation quarter

HEAD range Avg RSS Final RSS Peak RSS Avg PSS Final PSS Peak FD
1–50 182.0 MiB 156.1 MiB 234.0 MiB 179.1 MiB 153.1 MiB 57
51–100 188.1 MiB 173.5 MiB 237.6 MiB 185.2 MiB 170.5 MiB 54
101–150 189.0 MiB 164.8 MiB 237.9 MiB 185.8 MiB 161.7 MiB 57
151–200 190.9 MiB 136.4 MiB 239.5 MiB 188.1 MiB 133.3 MiB 54

Raw reports and per-navigation boundary samples: workflow run and full sequential-navigation-soak-results artifact.

Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Spider Bench A/B

✅ All benchmark browser service runs completed; results are informational.

Public HEAD: 184 / 240 rows; 38 / 48 sites produced rows; 10 unexpected empty sites.

✅ Deterministic fixture contract is clean.

Common ancestor d9928760ed20 → HEAD 7c4e73234642; benchmark order: base-first; workflow: success.

Public 48-site run · informational

Metric Base HEAD Δ
Run status success success —
Extracted rows / contract 184 / 240 184 / 240 0 (0.00%)
Contract fill 76.67% 76.67% 0.00 pp (0.00%)
Sites with rows 38 / 48 38 / 48 0 (0.00%)
Sites meeting row contract 36 / 48 36 / 48 0 (0.00%)
Unexpected empty sites 10 10 0 (0.00%)
Partial-row sites 2 2 0 (0.00%)
Site outcomes extracted: 36; HTTP error + rows: 2; empty: 7; HTTP error + empty: 1; snapshot error + empty: 2 extracted: 37; HTTP error + rows: 1; empty: 7; HTTP error + empty: 1; snapshot error + empty: 2 —
Observed duration 50.39 s 45.24 s -5.15 s (-10.22%)
Estimated CPU 53.58 s 49.42 s -4.16 s (-7.76%)
Peak PSS 281.25 MiB 277.55 MiB -3.70 MiB (-1.31%)
Peak RSS 287.41 MiB 281.23 MiB -6.18 MiB (-2.15%)
Peak threads 26 26 0 (0.00%)
Mismatched sites 0 0 0
Timeout with items 0 0 0
Category rows Base HEAD Δ
news 35 / 40 35 / 40 0
stocks 20 / 40 20 / 40 0
tech 35 / 40 35 / 40 0
sports 27 / 40 27 / 40 0
games 37 / 40 37 / 40 0
life 30 / 40 30 / 40 0

Public-site content, timing, and memory are noisy. This single A/B run reports evidence only; site outcome counts explain missing rows without treating them as a deterministic regression.

CPU and memory timelines

These are bounded 40-point views of the same complete process-tree samples used by the HTML report. CPU uses 100% per occupied logical core; memory lines are RSS first and PSS second when complete PSS samples are available.

Base

xychart-beta
    title "Base CPU"
    x-axis "Elapsed seconds" [1.539, 2.541, 3.042, 4.042, 5.544, 7.046, 8.548, 10.05, 11.051, 12.553, 14.055, 15.557, 17.059, 18.06, 19.64, 21.195, 22.697, 24.284, 25.785, 26.787, 27.788, 28.29, 29.794, 31.295, 32.796, 33.796, 35.298, 36.8, 38.302, 39.804, 40.806, 42.308, 43.809, 44.31, 45.311, 46.811, 47.812, 49.314]
    y-axis "CPU percent" 0 --> 500
    line [125.86, 97.79, 129.67, 115.99, 193.71, 151.83, 163.77, 203.72, 137.86, 93.92, 159.79, 43.92, 87.88, 127.82, 53.44, 97.85, 69.87, 121.9, 131.82, 99.82, 107.85, 105.76, 115.61, 107.85, 138.01, 106.01, 31.93, 105.95, 41.92, 121.82, 117.92, 151.78, 13.97, 3.99, 140.05, 148, 143.86, 183.64]
Loading
xychart-beta
    title "Base memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.039, 1.539, 2.541, 3.042, 4.042, 5.544, 7.046, 8.548, 10.05, 11.051, 12.553, 14.055, 15.557, 17.059, 18.06, 19.64, 21.195, 22.697, 24.284, 25.785, 26.787, 27.788, 28.29, 29.794, 31.295, 32.796, 33.796, 35.298, 36.8, 38.302, 39.804, 40.806, 42.308, 43.809, 44.31, 45.311, 46.811, 47.812, 49.314, 50.389]
    y-axis "Memory MiB" 0 --> 500
    line [12.56, 119.61, 128.06, 133.68, 140.33, 165.44, 190.2, 197.14, 205.46, 177.15, 166.48, 183.84, 172.59, 169.82, 167.31, 145.3, 164.54, 177.84, 159.93, 164.31, 208.35, 287.41, 229.75, 218.66, 174.79, 176.11, 188.95, 152.64, 161.83, 148.51, 188.43, 255.43, 221.16, 171.82, 170.49, 195.8, 168.09, 172.47, 201.69, 0]
    line [9.61, 116.45, 124.72, 130.51, 137.16, 162.27, 187.13, 194, 202.32, 174, 163.28, 180.85, 169.47, 166.67, 164.18, 142.09, 161.26, 174.5, 156.63, 161.05, 205.1, 281.25, 226.01, 215.43, 171.45, 172.91, 185.5, 149.29, 158.45, 145.09, 185.17, 251.96, 217.88, 168.25, 167.13, 192.43, 164.73, 169.7, 198.39, 0]
Loading

HEAD

xychart-beta
    title "HEAD CPU"
    x-axis "Elapsed seconds" [1.039, 1.54, 2.542, 4.054, 5.055, 6.559, 7.56, 9.06, 10.061, 11.563, 12.564, 14.065, 15.068, 16.569, 17.57, 19.072, 20.073, 21.576, 23.079, 24.08, 25.081, 25.582, 26.584, 28.086, 29.088, 30.59, 31.592, 33.094, 34.095, 35.597, 36.598, 38.099, 39.1, 40.601, 41.602, 43.104, 44.104, 44.604]
    y-axis "CPU percent" 0 --> 200
    line [21.93, 121.85, 79.77, 153.69, 133.87, 147.78, 161.79, 171.96, 135.83, 147.83, 141.81, 111.97, 15.98, 111.88, 61.9, 4, 69.91, 105.71, 125.76, 157.86, 109.88, 127.79, 151.64, 143.62, 135.75, 125.8, 117.76, 101.86, 89.89, 37.95, 141.92, 44, 17.97, 134.07, 81.88, 119.85, 120.01, 186.06]
Loading
xychart-beta
    title "HEAD memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.037, 1.039, 1.54, 2.542, 4.054, 5.055, 6.559, 7.56, 9.06, 10.061, 11.563, 12.564, 14.065, 15.068, 16.569, 17.57, 19.072, 20.073, 21.576, 23.079, 24.08, 25.081, 25.582, 26.584, 28.086, 29.088, 30.59, 31.592, 33.094, 34.095, 35.597, 36.598, 38.099, 39.1, 40.601, 41.602, 43.104, 44.104, 44.604, 45.239]
    y-axis "Memory MiB" 0 --> 500
    line [12.38, 78.74, 114.25, 125.17, 141.19, 159.81, 171.62, 163.88, 189.89, 191.99, 171.52, 187.93, 164.4, 146.52, 182.84, 175.57, 147.51, 146.91, 181.5, 160.24, 200.85, 281.23, 197.2, 198.91, 219.63, 156.41, 205.7, 196.81, 157.17, 156.96, 154.59, 193.09, 166.18, 154.08, 183.5, 179.58, 157.68, 171.14, 193.18, 0]
    line [9.29, 75.33, 110.81, 121.73, 137.74, 157.46, 168.36, 160.41, 186.57, 182.74, 168.71, 184.54, 161.06, 143.14, 180.35, 172.25, 144.23, 143.62, 178.22, 156.96, 196.29, 277.55, 194.41, 196.28, 216.37, 153.15, 199.82, 193.57, 154.03, 153.74, 152.08, 189.88, 162.91, 150.81, 180.26, 176.32, 154.51, 168.01, 189.9, 0]
Loading

Deterministic fixture · required contract

The fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.

Metric Base HEAD Δ
Run status success success —
Extracted rows / contract 40 / 40 40 / 40 0 (0.00%)
Contract fill 100.00% 100.00% 0.00 pp (0.00%)
Sites with rows 8 / 15 8 / 15 0 (0.00%)
Sites meeting row contract 15 / 15 15 / 15 0 (0.00%)
Unexpected empty sites 0 0 0
Partial-row sites 0 0 0
Site outcomes extracted: 7; HTTP error + rows: 1; empty: 3; timeout + empty: 4 extracted: 7; HTTP error + rows: 1; empty: 3; timeout + empty: 4 —
Observed duration 19.87 s 19.87 s -0.00 s (-0.01%)
Estimated CPU 0.43 s 0.40 s -0.03 s (-7.16%)
Peak PSS 66.60 MiB 66.57 MiB -0.03 MiB (-0.05%)
Peak RSS 69.63 MiB 69.72 MiB +0.10 MiB (+0.14%)
Peak threads 18 18 0 (0.00%)
Mismatched sites 0 0 0
Timeout with items 0 0 0

Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full spider-bench-results artifact.

The public-web A/B is informational. The exact HEAD fixture contract runs as a separate required CI check; timing and public-site content deltas remain non-blocking.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

CI Regression Report

Source CI run · source state at render: in_progress · artifacts: 6/6

Check Status Signal
Release regression ✅ HEAD/base failures 0/0; raw binary +0.013925%
Frontend differential ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes ✅ 8/8 Moli episodes passed; 0 failures
Runtime/CDP contracts ✅ 26 contract cases; 0 failures
CDP smoke ✅ 52/52 groups passed; 621 scenarios
WebMainBench ✅ 545/545 completed; 0 unexpected failures
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.013925%

Package and image size

Metric Base HEAD Delta Delta %
Raw binary 148.81 MiB 148.83 MiB +21.22 KiB +0.013925%
Stripped binary 102.46 MiB 102.48 MiB +20.00 KiB +0.019061%
gzip binary 51.06 MiB 51.06 MiB +7.06 KiB +0.013509%
Rootfs 155.71 MiB 155.73 MiB +20.00 KiB +0.012543%
gzip rootfs 59.94 MiB 59.95 MiB +12.74 KiB +0.020754%

Startup latency and PSS

Case Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta
Serve ready 27.34 ms 27.39 ms +0.06 ms 4.53 MiB 4.00 MiB −538.00 KiB
CDP first page 52.36 ms 50.76 ms −1.60 ms 4.39 MiB 4.02 MiB −378.00 KiB
CDP warm page 12.98 ms 12.53 ms −0.45 ms 50.12 MiB 50.00 MiB −121.50 KiB
CLI about:blank 16.91 ms 15.97 ms −0.93 ms 4.29 MiB 2.90 MiB −1.39 MiB
CLI local JS 20.55 ms 22.06 ms +1.50 ms 3.00 MiB 4.22 MiB +1.22 MiB

Concurrency matrix

Concurrency Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta HEAD failures Unstable B/H
1 19.94 ms 19.94 ms +0.00 ms 803.00 KiB 787.00 KiB −16.00 KiB 0 0/0
5 22.22 ms 21.24 ms −0.98 ms 27.38 MiB 12.97 MiB −14.42 MiB 0 0/0
10 22.11 ms 20.65 ms −1.46 ms 12.95 MiB 13.16 MiB +213.00 KiB 0 0/0
25 22.58 ms 21.46 ms −1.12 ms 27.63 MiB 21.75 MiB −5.87 MiB 0 0/0
100 22.17 ms 21.85 ms −0.31 ms 27.84 MiB 12.95 MiB −14.89 MiB 0 0/0
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Match DOM mismatch Diagnostic mismatch Moli error Reference error Infrastructure error Mismatched frames Duration
1,020 0 0 0 0 0 0 6m 52.99s
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Fast contract Episodes Passed Assertions Ready p50 Episode p50
Moli 8 8 47/47 3.45 ms 26.25 ms
Chromium 8 8 47/47 296.20 ms 89.91 ms
Operation p50 Chromium Moli Delta Delta %
navigate 47.12 ms 6.94 ms −40.18 ms −85.27%
observe 0.87 ms 0.95 ms +0.08 ms +9.22%
fill 3.34 ms 3.58 ms +0.24 ms +7.25%
click 5.20 ms 3.84 ms −1.36 ms −26.21%
Idle-resource episode Peak RSS Peak PSS Average CPU Peak CPU Peak processes Sampler
Moli 65.94 MiB 62.51 MiB 0.78% 10.00% 1 ✅
Chromium 1282.66 MiB 330.02 MiB 2.38% 89.43% 13 ⚠️ PSS partial
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
Suite Cases Failures Median case p50 Median case p95 Median peak PSS p50
Synthetic fetch 13 0 16.78 ms 17.65 ms 610.00 KiB
Long-lived CDP session 13 0 18.06 ms 18.54 ms —
CDP smoke — ✅ 52/52 groups passed; 621 scenarios

Workers: 4 · cumulative group time: 196.89 s · failed groups: 0

Slowest group Scenarios Duration Status
scrollbar-visibility 22 28.07 s ✅
target-lifecycle 24 17.32 s ✅
dom-input 27 13.50 s ✅
chromium-cdp 56 11.60 s ✅
multi-page 45 11.51 s ✅
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Completed Successful Expected DNS failure Unexpected failures Panics Crashes Timeouts Empty output
545/545 544 1 0 0 0 0 0

Frozen HTML · Linux · --wait done · 45 seconds per page · no retries. Content quality is evaluated separately.

Diagnostics: webmainbench-results — every page's Markdown, stderr, and exit status. Source run and artifacts

All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Closing after the consolidation audit. This belongs to an earlier experimental Markdown stack and was not part of the measured fixed build. Current failure evidence does not justify carrying its broad content heuristics into #1501, so it is intentionally not merged.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Reopened after correcting the consolidation scope: this is an independent pre-existing stack and should not have been closed as part of #1501 cleanup. Its original scope and base relationship are preserved; this does not add it to #1501.

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