Skip to content

Commit 6190221

Browse files
donislawdevclaude
andauthored
html: a page on one line, and styles in a sheet or in attributes (#179)
* html: a page on one line, and styles in a sheet or in attributes formatting=minified puts the whole page on one line with no newline at the end, and it shows the same as the page in lines. The catalogue of every element keeps a space where a line ended, and its pre keeps its line break as a character reference. The manifest says line_ending none. styles=embedded puts one list of CSS rules in a style element, in the head of a page and at the very start of a fragment. styles=inline puts the same rules in a style attribute on every element they are for, outside the catalogue. No rule names anything to fetch. Every piece of markup a page writes is now one entry of an array, and the other spellings are made from the plain one by two rules, so the default bytes are unchanged. The structural check is told both settings and asserts them, four new guards, three golden hashes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * html check: refuse styles that declare nothing and a stray carriage return The structural check took "p {}" and style="" for styles in both layouts, and a guard compared an empty rule with an empty attribute and called them one look. A rule and an attribute now have to hold one declaration, a property and a value. The rules of a sheet are read with a lookbehind, because on one line the brace of the last rule is all that stands before the next. A carriage return was refused only on a page of ASCII, so one in a page of other scripts went through, and a fragment of CRLF lines ended in a traceback. A page of lines now refuses any carriage return first. A guard hands the check pages from the program broken each of those ways and asks for a verdict, and a canary gives it an honest page on one line with a sheet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * site: the html settings formatting and styles in every language The formats page lists every setting of every format, and the guard that holds the site to what the program renders went red on all three systems once html had two settings more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent efc9f0d commit 6190221

42 files changed

Lines changed: 1200 additions & 126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,31 @@ because it turns other people's test suites red.
160160
- **HTML: pictures inside the page.** `inline`, `inline_format` and
161161
`inline_size` - the same settings, with the same meaning, as the pictures
162162
of an `eml` message - write real pictures of any picture format into the
163-
page as `data:` URLs, each on a line of its own above the blocks, so
163+
page as `data:` URLs, each in a paragraph of its own above the blocks, so
164164
opening the page fetches nothing. Each picture is the very file its format
165165
writes on its own. The Nu HTML Checker finds nothing wrong with a page of
166166
any of the nine formats, Chromium shows every format but `tiff`, and
167167
DOMPurify keeps them all. lxml, and BeautifulSoup on top of it, leave out
168168
a picture past about 7.1 MB unless told to read huge trees - on Linux lxml
169169
took over 20 seconds over such a page, and with a 15 MB picture it lost the
170170
rest of the page as well. Files made without pictures keep their bytes.
171+
- **HTML: a page on one line, and styles.** `formatting=minified` puts the
172+
whole page on one line with no newline at the end, the way a bundler
173+
writes it, and the page shows the same as one written in lines. A program
174+
reading line by line gets the whole page as one line - Go's
175+
`bufio.Scanner` refuses a line past 64 KB unless given a larger buffer -
176+
and text read by joining what the elements hold runs the last word of one
177+
block into the first word of the next. The manifest says `line_ending:
178+
none` for such a page. `styles=embedded` puts CSS rules in a style element,
179+
in the head of a page and at the very start of a fragment, and
180+
`styles=inline` puts the same rules in a style attribute on every heading,
181+
paragraph, list, table and quote the page is filled with. The Nu HTML
182+
Checker finds nothing wrong with either, and Chromium shows both the same.
183+
DOMPurify with its defaults drops the style element without listing it as
184+
removed and keeps the attributes, and lxml's `text_content` and
185+
BeautifulSoup on html5lib count the rules as text of the page. No rule
186+
names anything to fetch. Files made with the earlier settings keep their
187+
bytes.
171188
- **A length of time as a setting.** `duration`, `change_interval` and `keyframe_interval` take
172189
`10s`, `1m30s`, `1h`, `500ms` or `59.9s`, to the millisecond. A bare number
173190
is refused rather than read as seconds, and so is a length that does not

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ recipe. `tfg formats <id>` prints the allowed range or list for each:
621621
| `geojson` | `geometry`, `formatting`, `precision`, `altitude`, `vertices`, `holes`, `winding`, `antimeridian`, `unlocated`, `ids`, `bbox` |
622622
| `eml` | `body`, `text_encoding`, `charset`, `headers`, `recipients`, `line_endings`, `attachments`, `attachment_format`, `attachment_size`, `filename_style`, `message_depth`, `inline`, `inline_format`, `inline_size` |
623623
| `svg` | `width`, `height` |
624-
| `html` | `structure`, `nesting`, `characters`, `elements`, `bom`, `inline`, `inline_format`, `inline_size` |
624+
| `html` | `structure`, `nesting`, `characters`, `elements`, `bom`, `formatting`, `styles`, `inline`, `inline_format`, `inline_size` |
625625
| `yaml`, `toml` | none in this build - the document is a fixed shape, and a size is the only thing to ask for |
626626
627627
```

‎internal/format/htmlfile/blocks.go‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,56 @@ type blocks struct {
2525
// tail is what the closing record ends with, which is the only thing the
2626
// shape of the file changes down here.
2727
tail string
28+
// m is how the blocks are spelled. The words drawn are the same in every
29+
// spelling, so one seed fills a page of one line and a page of many with
30+
// the same blocks.
31+
m *markup
2832
}
2933

3034
// Shortest is the smallest closing record: an empty paragraph plus whatever
3135
// this shape closes after it.
32-
func (b blocks) Shortest() int64 { return int64(len(paraOpen) + len(b.tail)) }
36+
func (b blocks) Shortest() int64 { return int64(len(b.m[paraOpen]) + len(b.tail)) }
3337

34-
func (blocks) Append(dst []byte, rng *rand.Rand) []byte {
38+
func (b blocks) Append(dst []byte, rng *rand.Rand) []byte {
39+
m := b.m
3540
switch rng.IntN(5) {
3641
case 0:
37-
dst = append(dst, "<h2>"...)
42+
dst = append(dst, m[h2Open]...)
3843
dst = appendPhrase(dst, rng, 2+rng.IntN(3))
39-
return append(dst, "</h2>\n"...)
44+
return append(dst, m[h2Close]...)
4045
case 1:
41-
dst = append(dst, "<ul>\n"...)
46+
dst = append(dst, m[ulOpen]...)
4247
for i, n := 0, 2+rng.IntN(3); i < n; i++ {
43-
dst = append(dst, "<li>"...)
48+
dst = append(dst, m[liOpen]...)
4449
dst = appendPhrase(dst, rng, 3+rng.IntN(4))
45-
dst = append(dst, "</li>\n"...)
50+
dst = append(dst, m[liClose]...)
4651
}
47-
return append(dst, "</ul>\n"...)
52+
return append(dst, m[ulClose]...)
4853
case 2:
49-
dst = append(dst, "<table>\n<tr><th>id</th><th>field</th><th>value</th></tr>\n"...)
54+
dst = append(dst, m[tableOpen]...)
5055
for i, n := 0, 2+rng.IntN(3); i < n; i++ {
51-
dst = append(dst, "<tr><td>"...)
56+
dst = append(dst, m[rowOpen]...)
5257
dst = strconv.AppendInt(dst, int64(i+1), 10)
53-
dst = append(dst, "</td><td>"...)
58+
dst = append(dst, m[cellSep]...)
5459
dst = append(dst, words[rng.IntN(len(words))]...)
55-
dst = append(dst, "</td><td>"...)
60+
dst = append(dst, m[cellSep]...)
5661
dst = append(dst, words[rng.IntN(len(words))]...)
57-
dst = append(dst, "</td></tr>\n"...)
62+
dst = append(dst, m[rowClose]...)
5863
}
59-
return append(dst, "</table>\n"...)
64+
return append(dst, m[tableClose]...)
6065
case 3:
6166
// A real page carries entities, and an ampersand left raw is the
6267
// classic way a document stops being well formed. The fixture carries
6368
// one on purpose.
64-
dst = append(dst, "<blockquote><p>"...)
69+
dst = append(dst, m[quoteOpen]...)
6570
dst = appendPhrase(dst, rng, 4+rng.IntN(4))
6671
dst = append(dst, " &amp; "...)
6772
dst = appendPhrase(dst, rng, 2)
68-
return append(dst, "</p></blockquote>\n"...)
73+
return append(dst, m[quoteClose]...)
6974
default:
70-
dst = append(dst, paraOpen...)
75+
dst = append(dst, m[paraOpen]...)
7176
dst = appendPhrase(dst, rng, 12+rng.IntN(12))
72-
return append(dst, paraClose...)
77+
return append(dst, m[paraClose]...)
7378
}
7479
}
7580

@@ -79,7 +84,7 @@ func (blocks) Discard() {}
7984

8085
func (b blocks) AppendExact(dst []byte, rng *rand.Rand, n int64) []byte {
8186
start := len(dst)
82-
dst = append(dst, paraOpen...)
87+
dst = append(dst, b.m[paraOpen]...)
8388
used := int64(len(dst)-start) + int64(len(b.tail))
8489
dst = appendFiller(dst, n-used)
8590
return append(dst, b.tail...)

‎internal/format/htmlfile/catalogue.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const (
2929
smallPicture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAEUlEQVR42mNwaDiAFTEMLQkAYvNgAQlPC90AAAAASUVORK5CYII="
3030
sound = "data:audio/wav;base64,UklGRjQAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YRAAAACAgICAgICAgICAgICAgICA"
3131

32+
// preformatted is the text of the pre element, the one place in the
33+
// catalogue where a line break is text rather than layout. A page on one
34+
// line has to keep it, so it is named here and found by name.
35+
preformatted = "preformatted text\n keeps its spaces"
36+
3237
// catalogueHead is what the catalogue puts in the head of a page. base
3338
// names no address, so it changes nothing a link resolves to, and the icon
3439
// is empty data so a browser asks nobody for one.
@@ -52,8 +57,7 @@ const (
5257
<h5>Fifth level</h5>
5358
<h6>Sixth level</h6>
5459
<blockquote cite="#text"><p>A quotation in a block.</p></blockquote>
55-
<pre><code>preformatted text
56-
keeps its spaces</code></pre>
60+
<pre><code>` + preformatted + `</code></pre>
5761
<hr>
5862
<dl><dt>Term</dt><dd>Its description.</dd></dl>
5963
<ol start="3" reversed><li>three</li><li>two</li></ol>
@@ -143,13 +147,13 @@ func (s settings) catalogueHeadFor() string {
143147
if !s.every || s.shape != structureDocument {
144148
return ""
145149
}
146-
return catalogueHead
150+
return s.spelling()[headCatalogue]
147151
}
148152

149153
// catalogueBlocks is what the catalogue adds to the body.
150154
func (s settings) catalogueBlocks() string {
151155
if !s.every {
152156
return ""
153157
}
154-
return catalogueBody
158+
return s.spelling()[bodyCatalogue]
155159
}

‎internal/format/htmlfile/characters.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ const (
2929
`and entities &amp; &lt; &gt; &quot; &nbsp; &copy; &euro; &#8364; &#x1F600;.</p>` + "\n"
3030
)
3131

32-
// internationalBlocks is what the setting adds, nothing for ascii.
32+
// internationalBlocks is what the setting adds, nothing for ascii, in the
33+
// spelling of the page.
3334
func (s settings) internationalBlocks() string {
3435
if !s.international {
3536
return ""
3637
}
37-
return international
38+
return s.spelling()[scripts]
3839
}

‎internal/format/htmlfile/html.go‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ func init() {
5656
// than a comment.
5757
Label: format.LabelVisible,
5858
Oracle: "python-html",
59-
// Style sheets and a page on one line come later
60-
// (docs/HTML-2-2026-10-14.md section 8). Declaring only what is here
61-
// is what makes a recipe asking for them fail loudly instead of
62-
// quietly producing something else.
59+
// Links come later, if at all (docs/HTML-2-2026-10-14.md section 3,
60+
// B4). Declaring only what is here is what makes a recipe asking for
61+
// them fail loudly instead of quietly producing something else.
6362
Properties: properties(),
6463
GeneratorVersion: generatorVersion,
6564
Generator: generator{},
@@ -89,7 +88,7 @@ func (generator) PlanContext(ctx context.Context, r format.Request) (format.Plan
8988
return format.Plan{}, err
9089
}
9190

92-
pictures, pictureBytes, err := planPictures(ctx, r, s.pictures)
91+
pictures, pictureBytes, err := planPictures(ctx, r, s.pictures, s.spelling())
9392
if err != nil {
9493
return format.Plan{}, err
9594
}
@@ -110,8 +109,10 @@ func (generator) PlanContext(ctx context.Context, r format.Request) (format.Plan
110109
Exact: true,
111110
Determinism: format.DeterminismByte,
112111
Properties: map[string]any{
113-
"encoding": "utf-8",
114-
"line_ending": "lf",
112+
"encoding": "utf-8",
113+
// none for a page on one line: it has no line to end, and lf
114+
// would describe a file that is not there.
115+
"line_ending": s.lineEnding(),
115116
"doctype": doctype,
116117
"language": "en",
117118
},
@@ -154,9 +155,10 @@ func belowMinimum(s settings, requested, min int64) error {
154155
// the reason names, whatever else was asked.
155156
reason = core.Says("html.MinimumWithPictures", "the file holds whole blocks and every picture in base64, which is about a third larger than the picture itself, and together they need that much")
156157
case s.adds():
157-
reason = core.Says("html.MinimumWithSettings", "the file holds whole blocks and what %s, %s, %s and %s add to them, and together they need that much",
158+
reason = core.Says("html.MinimumWithSettings", "the file holds whole blocks and what %s, %s, %s, %s and %s add to them, and together they need that much",
158159
core.A("Nesting", core.LabelTerm(settingNesting)), core.A("Characters", core.LabelTerm(settingCharacters)),
159-
core.A("Elements", core.LabelTerm(settingElements)), core.A("BOM", core.LabelTerm(textenc.SettingBOM)))
160+
core.A("Elements", core.LabelTerm(settingElements)), core.A("BOM", core.LabelTerm(textenc.SettingBOM)),
161+
core.A("Styles", core.LabelTerm(settingStyles)))
160162
case s.shape == structureFragment:
161163
reason = core.Says("html.MinimumFragment", "a fragment holds whole blocks, and one of them needs that much")
162164
}
@@ -178,7 +180,8 @@ func belowMinimum(s settings, requested, min int64) error {
178180
// fit and what does it cost", and Plan answers "is this request askable at all".
179181
func labelledHead(s settings, r format.Request, min int64) (head, heading string, note *format.Note) {
180182
label := core.Label("html", r.Bytes, r.Seed)
181-
heading = "<h1>" + label + "</h1>\n"
183+
m := s.spelling()
184+
heading = m[labelOpen] + label + m[labelClose]
182185

183186
plain := s.prologue()
184187
head, extra := plain, int64(0)
@@ -229,5 +232,5 @@ func minimumBytes() int64 { return minimumFor(settings{shape: structureDocument}
229232
// whole block, computed from the pieces Write uses rather than written down so
230233
// it cannot drift away from the template.
231234
func minimumFor(s settings) int64 {
232-
return int64(len(s.prologue())) + s.openingBytes() + int64(len(paraOpen)) + s.tailBytes()
235+
return int64(len(s.prologue())) + s.openingBytes() + int64(len(s.spelling()[paraOpen])) + s.tailBytes()
233236
}

0 commit comments

Comments
 (0)