Move is_inline to HtmlElem (#6748)

This commit is contained in:
Laurenz 2025-08-12 16:27:39 +02:00 committed by GitHub
parent 57f85eb4fd
commit a7c8fd6872
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 13 deletions

View File

@ -125,9 +125,3 @@ fn last_char(nodes: &[HtmlNode]) -> Option<char> {
} }
None None
} }
/// Checks whether the given element is an inline-level HTML element.
pub fn is_inline(elem: &Content) -> bool {
elem.to_packed::<HtmlElem>()
.is_some_and(|elem| tag::is_inline_by_default(elem.tag))
}

View File

@ -17,7 +17,7 @@ use typst_library::text::SmartQuoter;
use typst_syntax::Span; use typst_syntax::Span;
use typst_utils::NonZeroExt; use typst_utils::NonZeroExt;
use crate::{HtmlDocument, HtmlElement, HtmlNode, attr, tag}; use crate::{HtmlDocument, HtmlElem, HtmlElement, HtmlNode, attr, tag};
/// Produce an HTML document from content. /// Produce an HTML document from content.
/// ///
@ -72,10 +72,7 @@ fn html_document_impl(
let arenas = Arenas::default(); let arenas = Arenas::default();
let mut info = DocumentInfo::default(); let mut info = DocumentInfo::default();
let children = (engine.routines.realize)( let children = (engine.routines.realize)(
RealizationKind::HtmlDocument { RealizationKind::HtmlDocument { info: &mut info, is_inline: HtmlElem::is_inline },
info: &mut info,
is_inline: crate::convert::is_inline,
},
&mut engine, &mut engine,
&mut locator, &mut locator,
&arenas, &arenas,

View File

@ -9,7 +9,7 @@ use typst_library::World;
use typst_library::routines::{Arenas, FragmentKind, Pair, RealizationKind, Routines}; use typst_library::routines::{Arenas, FragmentKind, Pair, RealizationKind, Routines};
use typst_library::text::SmartQuoter; use typst_library::text::SmartQuoter;
use crate::HtmlNode; use crate::{HtmlElem, HtmlNode};
/// Produces HTML nodes from content contained in an HTML element that is /// Produces HTML nodes from content contained in an HTML element that is
/// block-level by default. /// block-level by default.
@ -114,7 +114,7 @@ fn realize_fragment<'a>(
RealizationKind::HtmlFragment { RealizationKind::HtmlFragment {
// We ignore the `FragmentKind` because we handle both uniformly. // We ignore the `FragmentKind` because we handle both uniformly.
kind: &mut FragmentKind::Block, kind: &mut FragmentKind::Block,
is_inline: crate::convert::is_inline, is_inline: HtmlElem::is_inline,
}, },
engine, engine,
locator, locator,

View File

@ -97,6 +97,12 @@ impl HtmlElem {
self self
} }
} }
/// Checks whether the given element is an inline-level HTML element.
fn is_inline(elem: &Content) -> bool {
elem.to_packed::<HtmlElem>()
.is_some_and(|elem| tag::is_inline_by_default(elem.tag))
}
} }
/// An element that lays out its content as an inline SVG. /// An element that lays out its content as an inline SVG.