The Machines · Runtime stack

seedhtml

A reckoner seed: html's tolerant parse and write, over seedxml's tree shape — machines/seeds/seedhtml.shoddy

the seedhtml machine's icon

Summary

seedhtml bridges html into the reckoner calculator. That machine answers the same Xml tree xml does. Its own reader accepts tag soup — sloppy HTML with missing or unclosed tags — that xml's would refuse. Its own writer knows which elements are void (they never take a closing tag, like <br>) and which are raw-text. The bridge is therefore the same one: this seed Includes seedxml to reuse XcOfXml/XcToXml rather than duplicate the tree shape. So an element from either machine is the same { "elem" tag attrs kids } at the keyboard.

Why It's Useful

The five words here look like seedxml's with the letters changed. The reason to have both is what happens on real input. html.shoddy's reader is tolerant where xml's is strict. An unclosed paragraph, a void element with no slash, a list whose items never close — that is the tag soup actual pages are made of. xml refuses all of it, correctly, because that is not XML. So the same document parses under one and not the other. Having only the strict pair would mean a session that can read documents nobody writes.

The writer differs for the matching reason: it knows which elements are void and which hold raw text. So HTMLTEXT emits <br> rather than closing it, and leaves a <script> body unescaped. Everything else — the tree shape, the attribute dict, the guarded file words — is shared with seedxml rather than duplicated. An element from either machine is the same thing at the keyboard.

User's Guide

The whole case for the seed, in two lines. The same string, to the tolerant reader and then to the strict one:

> "<p>one<br>two" HTMLPARSE HTMLTEXT
x: "<p>one<br>two</p>"
> CLEAR "<p>one<br>two" XMLPARSE
?: XMLPARSE: UNTERMINATED ELEMENT <br> AT 14

HTMLPARSE closed the paragraph, left the void element alone, and answered a tree. XMLPARSE was right to refuse — that string is not XML.

The same tolerance over a list whose items never close, printed back indented:

> "<ul><li>a<li>b</ul>" HTMLPARSE 2 HTMLPRETTY
x: "<ul>
  <li>a</li>
  <li>b</li>
</ul>
"

Attributes carry the same typing caveat seedxml's guide explains — use the apostrophe form at a prompt, or HTMLLOAD for anything longer than a line.

Word Reference

WordDescription
HTMLPARSE ( str -- doc )The string, parsed as (tolerant) HTML — an element is { "elem" tag attrs kids }, and attrs is a dict.
HTMLTEXT ( doc -- str )The value, written out as HTML text.
HTMLPRETTY ( doc n -- str )The value, written out as HTML text indented n spaces per level.
HTMLLOAD ( path -- doc )The file, read and parsed as HTML — a refusal names why it could not be, whether that is the file or the syntax.
HTMLSAVE ( path doc -- ok )Write the value to path as HTML text; True on success.

Who Uses It

UserHow
halifaxThe calculator's HTML words: HTMLPARSE, HTMLTEXT, HTMLPRETTY, HTMLLOAD and HTMLSAVE.
sparkySparky folds it too, so a model calling eval reaches the same words halifax puts at a prompt.

A mill claims this seed by folding RckSeedHtml over its reckoner state, which is all halifax does.

The Machines It Uses

MachineWhy
cuttleThe Cell type every bridged word reads its arguments from and answers into.
htmlThe domain this seed bridges: HtmlRead, HtmlText, HtmlPretty.
reckonerRckReg and the argument readers every registered word is built from.
seedxmlXcOfXml/XcToXml, reused rather than duplicated.
xmlThe Xml/XRead types html.shoddy answers, needed directly since seedxml's own Include of it is not re-exported.