Expand description
Terminal-native HTML for tuika.
Two ways in, one engine behind both:
HtmlRendererplugs into markdown through tuika’sMarkdownBlockRendererseam. One implementation handles raw<details>,<table>, and<div>blocks as well as```htmlfences.Htmlis aView, the standalone viewer: hand it a fragment, place it in a layout, and it paints likeMarkdowndoes.
use tuika::prelude::*;
use tuika_html::{Html, HtmlRenderer};
// In markdown:
let renderer = HtmlRenderer::new();
let doc = Markdown::new("<details><summary>Notes</summary>Body</details>")
.block_renderer(&renderer);
// Standalone:
let view = Html::new("<h1>Title</h1><p>Prose with <b>bold</b>.</p>");§What renders
Headings, paragraphs, lists (ordered, unordered, nested), definition lists,
block quotes, <pre>, <hr>, <table>, <details>/<summary>, and the
presentational inline elements — <b>, <em>, <code>, <kbd>, <mark>,
<a>, <img> (as alt text), <br>, <sub>, <sup>. Unknown elements stay
transparent, so their text still shows. <script>, <style>, and embedded
objects are dropped with their content.
Styling resolves through the active StyleSheet roles rather than colors
of its own, so HTML inherits the host’s theme along with everything else on
the screen.
§What does not
There is no CSS, no style attribute, no floats or positioning, and no
layout that depends on the document outside the fragment. This renders
content, not pages — the goal is that HTML in a transcript reads as well as
the markdown around it, not that a terminal becomes a browser.
§Untrusted input
HTML in a transcript is untrusted. Control bytes are stripped before any text
becomes a cell, so markup can never emit terminal commands; input, output,
and nesting are bounded by Limits, and exceeding either the input-size or
the nesting bound returns None (markdown then drops the block) rather than
doing unbounded work. Nesting is measured on the source before parsing,
because html5ever builds — and drops — its tree recursively, and deep enough
markup overflows the stack inside the size bound. No network is touched:
<img> becomes its alt text, never a fetch.
Structs§
- Html
- A view that renders an HTML fragment to its area.
- Html
Renderer - Renders HTML for tuika’s structured markdown block seam.
- Limits
- Bounds on one render.
Functions§
- to_
lines - Render an HTML fragment to width-fitted styled lines.
- to_
lines_ with_ limits to_lineswith explicitLimits:Nonewhen the input is overmax_input_bytes.