Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
934d501
fix(fetch): preserve rendered document content
lanyue-llk Sep 24, 2026
92a76a7
fix(renderer): retain content behind loading veils
lanyue-llk Sep 24, 2026
eabea47
test(fetch): align markdown regressions with preserved semantics
lanyue-llk Sep 24, 2026
be2ff8d
fix(fetch): preserve interactive document semantics
lanyue-llk Sep 26, 2026
35178ba
fix(fetch): close content audit regressions
lanyue-llk Sep 28, 2026
7450ce0
fix(html2md): keep preformatted blocks as markdown code
lanyue-llk Sep 28, 2026
9ab29d3
fix(html2md): expose table code as markdown
lanyue-llk Sep 28, 2026
1486f8c
fix(content): preserve semantic pre and visibility relationships
lanyue-llk Sep 28, 2026
3303fad
fix(content): preserve rendered semantics across fallbacks
lanyue-llk Sep 28, 2026
766f247
fix(content): preserve completed loading transitions
lanyue-llk Sep 28, 2026
f1a9055
fix(content): preserve semantic streams and disclosure boundaries
lanyue-llk Sep 29, 2026
d69da75
fix(content): preserve proven interactive disclosures
lanyue-llk Sep 29, 2026
0ac34b9
fix(renderer): retain bounded fade-in content
lanyue-llk Sep 29, 2026
3be2093
fix(content): close semantic boundary regressions
lanyue-llk Sep 29, 2026
7b35185
fix(content): honor effective style and disclosure facts
lanyue-llk Sep 29, 2026
f93a23a
fix(content): trust scoped state over handler shape
lanyue-llk Sep 29, 2026
c5efa39
fix(content): consume resolved style semantics
lanyue-llk Sep 29, 2026
8c01910
chore(deps): retain regenerated lock resolution
lanyue-llk Sep 29, 2026
c078c4a
fix(content): preserve animation list semantics
lanyue-llk Sep 30, 2026
ee104df
fix(content): compose final animation effects
lanyue-llk Sep 30, 2026
4f556a6
chore(deps): restore content style support
lanyue-llk Oct 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ curl-sys = { git = "https://github.com/lexmount/curl-rust", rev = "a0ea59f5ca1b1
cookie = { git = "https://github.com/ldm0/cookie-rs", branch = "priority" }
v8 = { path = "vendor/v8-152.2.0" }
deno_v8 = { path = "vendor/deno_v8-0.3.0" }
selectors = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
servo_arc = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
stylo = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
stylo_atoms = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
stylo_dom = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
stylo_static_prefs = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
stylo_traits = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
selectors = { git = "https://github.com/lexmount/stylo", rev = "1032a2947ec2f7cee1027d07084203be87e17643" }
servo_arc = { git = "https://github.com/lexmount/stylo", rev = "1032a2947ec2f7cee1027d07084203be87e17643" }
stylo = { git = "https://github.com/lexmount/stylo", rev = "1032a2947ec2f7cee1027d07084203be87e17643" }
stylo_atoms = { git = "https://github.com/lexmount/stylo", rev = "1032a2947ec2f7cee1027d07084203be87e17643" }
stylo_dom = { git = "https://github.com/lexmount/stylo", rev = "1032a2947ec2f7cee1027d07084203be87e17643" }
stylo_static_prefs = { git = "https://github.com/lexmount/stylo", rev = "1032a2947ec2f7cee1027d07084203be87e17643" }
stylo_traits = { git = "https://github.com/lexmount/stylo", rev = "1032a2947ec2f7cee1027d07084203be87e17643" }
svgtypes = { git = "https://github.com/lexmount/svgtypes", branch = "feat/strict-path-numbers" }
taffy = { git = "https://github.com/ldm0/taffy", rev = "645bf5a49df607a8bff34ec90c5343901d04f10e" }

Expand Down
26 changes: 17 additions & 9 deletions moli-html2md/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,22 @@ missing trailing cells in short rows; the converter does not allocate a padded g

Tables with `role="presentation"` or `role="none"` retain ordinary block expansion,
in DOM order with blank lines between cells, even when structurally simple. Role
matching ignores ASCII case and surrounding HTML whitespace. The same fallback
applies to complex tables: non-unit spans, multiple `thead` rows, rows wider than
matching ignores ASCII case and surrounding HTML whitespace. Complex tables use
content-only HTML: non-unit spans, multiple `thead` rows, rows wider than
an explicit header, or cells containing nested tables, lists, headings, quotes
or preformatted blocks. Inner simple tables can still produce GFM when their
containing layout table is expanded. Other roles, borders and CSS do not select
another conversion path. Complex layouts remain readable blocks instead of raw
HTML tables.
or preformatted blocks. This retains header, cell and nested-table associations
that Markdown pipe tables cannot express. Inner simple tables can still produce
GFM when an explicitly presentational containing table is expanded. Scripts,
styles and event handlers are omitted from HTML table output.

Supported output includes headings, paragraphs, emphasis, strikethrough, links,
images, lists, blockquotes, hard breaks, and fenced code. Inline HTML is used when
images, lists, blockquotes, hard breaks, media source links, separated form choices,
and fenced code. Inline HTML is used when
Markdown delimiters cannot express an emphasis boundary.
Superscripts and subscripts retain their HTML markers. Complete author-supplied
TeX spans retain their commands and indices. Native MathML retains mathematical
markup and presentation attributes, with alternate annotations omitted, so
fractions, roots, matrices and powers do not collapse into ambiguous plain text.
Script/style/head/noscript/template subtrees are omitted.

`max_depth` counts the supplied root as depth zero; nodes at or beyond the limit
Expand All @@ -89,8 +94,11 @@ spaces and blank lines. Empty blocks still separate surrounding text.

This is a structural content dump. It omits non-rendered serialized state blobs
but retains content in collapsed panels and inactive tabs. It does not evaluate
stylesheets, layout, or JavaScript, and cannot preserve all HTML presentation (for example, arbitrary
ordered-list numbering or table spanning). DOM snapshots used by Moli's optional
stylesheets, layout, or JavaScript. Callers may supply computed block boundaries
through the optional DOM query. Moli's page exporter additionally filters current
CSS-hidden UI while retaining explicitly linked disclosure content. The converter
cannot preserve all HTML presentation (for example, arbitrary ordered-list numbering).
DOM snapshots used by Moli's optional
strip/base/frame transformations remain the responsibility of the caller.

## Verification
Expand Down
178 changes: 178 additions & 0 deletions moli-html2md/src/anchors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
use std::collections::HashSet;

use crate::{Dom, NodeKind};

pub(crate) struct Targets {
referenced: HashSet<String>,
ids: HashSet<String>,
}

impl Targets {
pub(crate) fn is_empty(&self) -> bool {
self.referenced.is_empty()
}

pub(crate) fn contains(&self, value: &str) -> bool {
self.referenced.contains(value)
}

pub(crate) fn targets<'a, D: Dom + ?Sized>(&self, dom: &'a D, node: D::NodeId) -> Vec<&'a str> {
let mut targets = Vec::with_capacity(2);
if let Some(id) = dom.attribute(node, "id").filter(|id| self.contains(id)) {
Comment thread
lanyue-llk marked this conversation as resolved.
Resolved
targets.push(id);
}
if dom.node_kind(node) == NodeKind::Element("a")
&& let Some(name) = dom
.attribute(node, "name")
.filter(|name| self.contains(name) && !self.ids.contains(*name))
&& !targets.contains(&name)
{
targets.push(name);
}
targets
}
}

pub(crate) fn referenced<D: Dom + ?Sized>(dom: &D, root: D::NodeId, limit: usize) -> Targets {
let mut available = HashSet::new();
let mut element_ids = HashSet::new();
if !dom.may_have_fragment_links() {
return Targets {
referenced: available,
ids: element_ids,
};
}
walk(dom, root, limit, |node| {
for attribute in ["id", "name"] {
if attribute == "name" && dom.node_kind(node) != NodeKind::Element("a") {
continue;
}
if let Some(value) = dom.attribute(node, attribute) {
available.insert(value.to_owned());
if attribute == "id" {
element_ids.insert(value.to_owned());
}
}
}
false
});
let mut referenced = HashSet::new();
walk(dom, root, limit, |node| {
if let Some(fragment) = dom
.attribute(node, "href")
.and_then(|href| href.strip_prefix('#'))
&& !fragment.is_empty()
{
// HTML fragment navigation tries the literal fragment first and
// only percent-decodes it when no literal target exists.
if available.contains(fragment) {
referenced.insert(fragment.to_owned());
} else {
let decoded = decode_fragment(fragment);
if available.contains(&decoded) {
referenced.insert(decoded);
}
}
}
false
});
Targets {
referenced,
ids: element_ids,
}
}

pub(crate) fn contains<D: Dom + ?Sized>(
dom: &D,
root: D::NodeId,
limit: usize,
ids: &Targets,
) -> bool {
walk(dom, root, limit, |node| !ids.targets(dom, node).is_empty())
}

pub(crate) fn within<D: Dom + ?Sized>(
dom: &D,
root: D::NodeId,
limit: usize,
ids: &Targets,
) -> Vec<String> {
let mut found = Vec::new();
walk(dom, root, limit, |node| {
for id in ids.targets(dom, node) {
if !found.iter().any(|existing| existing == id) {
found.push(id.to_owned());
}
}
false
});
found
}

fn walk<D: Dom + ?Sized>(
dom: &D,
root: D::NodeId,
limit: usize,
mut found: impl FnMut(D::NodeId) -> bool,
) -> bool {
let mut stack = vec![(Some(root), 0, false)];
while let Some((node, depth, siblings)) = stack.pop() {
let Some(node) = node else {
continue;
};
if siblings {
stack.push((dom.next_sibling(node), depth, true));
}
if depth >= limit {
continue;
}
if matches!(
dom.node_kind(node),
NodeKind::Other
| NodeKind::Element("head" | "script" | "style" | "noscript" | "template")
) {
continue;
}
if found(node) {
return true;
}
stack.push((dom.first_child(node), depth + 1, true));
}
false
}

pub(crate) fn decode_fragment(fragment: &str) -> String {
let bytes = fragment.as_bytes();
let mut decoded = Vec::with_capacity(bytes.len());
let mut offset = 0;
while offset < bytes.len() {
if bytes[offset] == b'%' && offset + 2 < bytes.len() {
let hex = |byte: u8| (byte as char).to_digit(16);
if let (Some(high), Some(low)) = (hex(bytes[offset + 1]), hex(bytes[offset + 2])) {
decoded.push((high * 16 + low) as u8);
offset += 3;
continue;
}
}
decoded.push(bytes[offset]);
offset += 1;
}
String::from_utf8(decoded).unwrap_or_else(|_| fragment.to_owned())
}

pub(crate) fn markup(id: &str) -> String {
let mut result = String::from("<a id=\"");
for character in id.chars() {
match character {
'&' => result.push_str("&amp;"),
'"' => result.push_str("&quot;"),
'<' => result.push_str("&lt;"),
'>' => result.push_str("&gt;"),
'\n' => result.push_str("&#10;"),
'\r' => result.push_str("&#13;"),
character => result.push(character),
}
}
result.push_str("\"></a>");
result
}
Loading
Loading