diff --git a/changelog/unreleased/2026-11-28-web-export-inline-links.md b/changelog/unreleased/2026-11-28-web-export-inline-links.md new file mode 100644 index 000000000..a0b4b3a2c --- /dev/null +++ b/changelog/unreleased/2026-11-28-web-export-inline-links.md @@ -0,0 +1 @@ +- **`--html` keeps styled spans inside inline links on the same line.** `BASE_CSS` now applies `display: inline; position: static` to all descendants of a text element (`[data-rune-static] .t *`) instead of direct children only, so styled `` runs inside `` stay inline with surrounding prose while standalone link containers keep their flex layout. diff --git a/crates/rune/src/runtime/web/export/page.rs b/crates/rune/src/runtime/web/export/page.rs index d8ccd8a19..f00e9021a 100644 --- a/crates/rune/src/runtime/web/export/page.rs +++ b/crates/rune/src/runtime/web/export/page.rs @@ -8,8 +8,9 @@ use std::fmt::Write; use super::ExportNode; /// The rule every exported element starts from: a Rune element is a flex row, positioned, with -/// its border inside its size. A text element (class `t`) holds inline runs instead. -pub(crate) const BASE_CSS: &str = "[data-rune-static],[data-rune-static] *{box-sizing:border-box;display:flex;position:relative;margin:0;padding:0;min-width:0;border:0 solid transparent}[data-rune-static] a{color:inherit;text-decoration:none}[data-rune-static] .t>*{display:inline;position:static}[data-rune-static] img{display:block}:where([data-rune-static]) img{height:auto}[data-rune-static] svg{display:block;position:absolute;inset:0}"; +/// its border inside its size. A text element (class `t`) holds inline runs (including styled +/// spans nested inside inline links) instead. +pub(crate) const BASE_CSS: &str = "[data-rune-static],[data-rune-static] *{box-sizing:border-box;display:flex;position:relative;margin:0;padding:0;min-width:0;border:0 solid transparent}[data-rune-static] a{color:inherit;text-decoration:none}[data-rune-static] .t *{display:inline;position:static}[data-rune-static] img{display:block}:where([data-rune-static]) img{height:auto}[data-rune-static] svg{display:block;position:absolute;inset:0}"; /// The value a property takes where a width sets nothing, matching `BASE_CSS`. fn initial(prop: &str) -> &'static str { diff --git a/crates/rune/src/runtime/web/export/tests.rs b/crates/rune/src/runtime/web/export/tests.rs index 296af81b3..d0a8d19c6 100644 --- a/crates/rune/src/runtime/web/export/tests.rs +++ b/crates/rune/src/runtime/web/export/tests.rs @@ -60,7 +60,7 @@ fn folds_widths_into_media_rules_and_hides_what_a_width_lacks() { assert!(media.contains("flex-direction:row"), "{media}"); assert!(!body.contains("Wide only"), "the body is the narrowest tree: {body}"); assert!(wide.iter().any(|n| n.inner == "Wide only")); - assert!(css.contains(".t>*{display:inline"), "a text element's runs stay inline: {css}"); + assert!(css.contains(".t *{display:inline;position:static}"), "a text element's inline runs and nested spans stay inline: {css}"); assert!(body.contains("

, all under .t. + let prose = nodes.iter().find(|n| n.path.ends_with("prose")).expect("prose"); + assert!(prose.text, "paragraph exports with class t"); + assert_eq!( + prose.inner, + "See the setup guide and rune_export docs for details.", + ); + + // Heading also exports with class t and nested . + let heading = nodes.iter().find(|n| n.path.ends_with("heading")).expect("heading"); + assert_eq!(heading.tag, "h2"); + assert!(heading.text, "heading exports with class t"); + assert_eq!(heading.inner, "Read the API"); + + // BASE_CSS uses a descendant selector under .t after the global flex rule so grandchildren + // like `.t a span` get `display:inline;position:static` instead of `display:flex`. + let base_flex = css.find("[data-rune-static] *{box-sizing:border-box;display:flex;position:relative").expect("base flex rule"); + let inline_rule = css.find("[data-rune-static] .t *{display:inline;position:static}").expect("descendant inline rule"); + assert!(inline_rule > base_flex, "inline rule must follow base flex rule: {css}"); + assert!(!css.contains(".t>*"), "direct-child selector would leave `.t a span` as display:flex: {css}"); + + // Standalone link container stays outside `.t` and keeps its flex column layout; its inner + // text children remain `.t` elements so their own styled spans stay inline. + let card = nodes.iter().find(|n| n.path.ends_with("card")).expect("card link container"); + assert_eq!(card.tag, "a"); + assert!(!card.text, "standalone link container must not carry class t"); + assert!(card.decls.contains(&("flex-direction", "column".into())), "{:?}", card.decls); + assert!(card.decls.contains(&("row-gap", "8px".into())), "{:?}", card.decls); + let card_open = body.split("').next().unwrap(); + assert!(!card_tag.contains("class=\"t ") && !card_tag.contains("class=\"t\""), "card must not have class t: "); + assert!( + body.contains("bold copy"), + "rich text inside standalone link container keeps its own .t scope: {body}", + ); +}