Skip to main content

Crate damascene_html

Crate damascene_html 

Source
Expand description

HTML → Damascene El transformer.

use damascene_core::prelude::*;
use damascene_html::html;

let tree: El = html("<h1>Hi</h1><p>Hello <strong>world</strong>.</p>");

damascene-html is a focused HTML-to-El transformer, not a browser engine. The thesis: Damascene’s widget kit already echoes most of HTML’s semantic vocabulary (text_runs<p>, hard_break<br>, span modifiers ≈ inline tags, bullet_list<ul>, code_block<pre><code>, table<table>, …), so a parse through html5ever plus a tag-by-tag mapping onto the existing widget vocabulary produces a faithful render for the subset of HTML that actually fits.

Supported coverage (per docs/HTML_VISION.md):

  • Tier 1 — direct widget mapping. Headings <h1><h3> (h4–h6 clamp to h3), paragraphs with the inline tag set (<strong>/<b>, <em>/<i>, <u>, <s>/<strike>/<del>, <code>, <a href>, <br>, <kbd>, <mark>), <ul> / <ol> / <li> with nesting + GFM task-list shape, <blockquote>, <pre><code class="language-X">, <hr>, full table tag family, <img> placeholders.
  • Tier 2A — inline style="...". Color, background, padding, border, radius, opacity, width/height + min/max, text-align, font-size/weight/style, text-decoration.
  • Tier 2B — <style> blocks + selectors. Tag / class / id / compound / comma-grouped selectors with full specificity sort. At-rules and unsupported selector shapes drop with lint findings.
  • Tier 2C — generic containers. <div>, <section>, <details>, <figure>, <button>, <input type="checkbox"> (all cosmetic).
  • Tier 2D — layout reshape + lint surface. display: flex + flex-direction, align-items, justify-content, overflow (hidden → clip, auto/scroll → wrap in scroll), box-shadow (blur extracted), font-family monospace detection, and margin* reconciled into parent gap. Properties without an Damascene equivalent (position, float, vh/vw/fr, display: grid, …) drop with Findings exposed through the _with_lints entry points.

Tier 3 (security-dropped: <script>, <iframe>, <object>, <embed>, <noscript>, every on* attribute, every javascript: / vbscript: / data:text/html URL) is enforced always. Embedders handling untrusted HTML should still layer a dedicated sanitizer (e.g. ammonia) in front.

Structs§

Finding
One lint occurrence. detail is a human-readable hint: the dropped property name + value, the collided margin pair, the unsupported selector text, and so on.
HtmlOptions
Optional knobs for crate::html_with_options.

Enums§

FindingKind
What was dropped or coerced, in a single dimension. The transformer emits at most one finding per (node, kind) tuple, so a single element with three unsupported properties produces three findings.

Functions§

html
Render an HTML document as an Damascene El. Returns a column([...]) of block-level Damascene widgets — the same shape an author would have hand-written, and the same shape damascene_markdown::md returns.
html_blocks
Like html_with_options but returns the block-level Els directly instead of wrapping them in a column. Intended for callers (e.g. damascene-markdown’s block-HTML event handler) that already have a containing block frame and just want the produced children appended.
html_blocks_with_lints
Lints-returning sibling of html_blocks. The reconciled gap is not surfaced — the calling block frame already owns its rhythm — but margin-asymmetry findings still land in the result.
html_fragment_inline
Inline-only entry point: parse input as an HTML fragment and return the inline runs it produces. The intended caller is damascene-markdown’s Event::InlineHtml handler, which buffers consecutive inline-HTML events into one string, hands the buffer here, and appends the produced runs to the open paragraph / heading / link / table cell.
html_fragment_inline_with_lints
Lints-returning sibling of html_fragment_inline.
html_with_lints
Like html_with_options but also returns the lint findings gathered during the walk. Use this when you need to surface dropped declarations, unsupported selectors, or margin-asymmetry reconciliations to the author or downstream tools.
html_with_options
Render an HTML document with explicit options.