diff options
| author | Michael Färber <01mf02@gmail.com> | 2024-12-10 10:57:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 09:57:22 +0000 |
| commit | 17f20c6944d569d5f0bb57caee37d9f208d87d0d (patch) | |
| tree | 9e48c3a6525adb876d06711bc48ef82eb64e59ff /crates/typst-library/src/html | |
| parent | bb0c8140950b3eec020a4f0147bbc4ea65f3952a (diff) | |
Basic HTML pretty-printing (#5533)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-library/src/html')
| -rw-r--r-- | crates/typst-library/src/html/dom.rs | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/crates/typst-library/src/html/dom.rs b/crates/typst-library/src/html/dom.rs index ee94279f..3d558fb0 100644 --- a/crates/typst-library/src/html/dom.rs +++ b/crates/typst-library/src/html/dom.rs @@ -470,6 +470,59 @@ pub mod tag { wbr } + /// Whether nodes with the tag have the CSS property `display: block` by + /// default. + /// + /// If this is true, then pretty-printing can insert spaces around such + /// nodes and around the contents of such nodes. + /// + /// However, when users change the properties of such tags via CSS, the + /// insertion of whitespace may actually impact the visual output; for + /// example, <https://www.w3.org/TR/css-text-3/#example-af2745cd> shows how + /// adding CSS rules to `<p>` can make it sensitive to whitespace. In such + /// cases, users should disable pretty-printing. + pub fn is_block_by_default(tag: HtmlTag) -> bool { + matches!( + tag, + self::html + | self::head + | self::body + | self::article + | self::aside + | self::h1 + | self::h2 + | self::h3 + | self::h4 + | self::h5 + | self::h6 + | self::hgroup + | self::nav + | self::section + | self::dd + | self::dl + | self::dt + | self::menu + | self::ol + | self::ul + | self::address + | self::blockquote + | self::dialog + | self::div + | self::fieldset + | self::figure + | self::figcaption + | self::footer + | self::form + | self::header + | self::hr + | self::legend + | self::main + | self::p + | self::pre + | self::search + ) + } + /// Whether the element is inline-level as opposed to being block-level. /// /// Not sure whether this distinction really makes sense. But we somehow @@ -480,7 +533,7 @@ pub mod tag { /// <https://www.w3.org/TR/html401/struct/global.html#block-inline> /// <https://developer.mozilla.org/en-US/docs/Glossary/Inline-level_content> /// <https://github.com/orgs/mdn/discussions/353> - pub fn is_inline(tag: HtmlTag) -> bool { + pub fn is_inline_by_default(tag: HtmlTag) -> bool { matches!( tag, self::abbr |
