Skip to content

Drop template indentation from API pages before writing them - #4959

Open
akira28 wants to merge 7 commits into
feature/api-property-path-oncefrom
feature/api-webmarkupmin
Open

akira28 wants to merge 7 commits into
feature/api-property-path-oncefrom
feature/api-webmarkupmin

Conversation

@akira28

@akira28 akira28 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

API pages are now written without their template indentation. API HTML is another 1.9% smaller, and 12 more pages get under Googlebot's 2 MB limit. The parsed pages are unchanged, and the docs build takes the same time.

Affects: API reference

Stack: 4 of 4, on top of #4956, #4955 and #4953.

Prompt summary: Finish the stack with the simpler whitespace collapse from #4944 instead of the WebMarkupMin minifier from #4945. The goal behind the stack is elastic/docs-eng-team#1183: bring API pages under Googlebot's 2 MB HTML limit.

Why

After #4952 to #4956, 58 API pages are still over 2 MB, many of them only just. The property row partial repeats thousands of times on those pages, and its tabs and line breaks are written out each time.

What

Each API page is rendered in memory and written without its indentation

OpenApiGenerator renders each page into a MemoryFileSystemStream. HtmlWhitespace.Collapse then turns every whitespace run in text that holds a line break into one line break, which renders the same under white-space: normal. Tags with their attribute values, comments, and pre, textarea, script and style elements are kept as they are. Only HTML's own whitespace counts, so a non-breaking space is never dropped.

A single pass, not a regex

#4944 did this with a regex over the whole page. Measured over all 7,243 API pages, that regex took 25 s and barely sped up on 18 threads (23 s). In one build it ran past its 10 s match timeout on the largest pages, so the whole Kibana and Elasticsearch APIs failed to generate. It also dropped a non-breaking space that sat next to a line break. HtmlWhitespace now walks the page once, copying markup through and collapsing only the whitespace in text. It takes 2.2 s over the same pages and gives the same output on every one of them.

Results

An isolated build of docs/ with the native AOT binary:

main #4956 This PR
All API HTML (7,243 pages) 2.56 GB 1.947 GB 1.910 GB
API pages over 2 MB 71 58 46
Docs build, two runs each, alternated 59 s, 68 s 65 s, 68 s
  • Same pages: I compared 153 pages with Print an API property's path once #4956's build: every start tag, its attributes, and the text with whitespace normalized. No page differs.
  • pre blocks: all 3,413 pre blocks in the Elasticsearch operation pages are byte-identical.

The WebMarkupMin variant of this step (#4945) reaches 41 pages over 2 MB, but adds about 55 s to every build, a dependency, and a workaround for hidden="until-found".

Out of scope: the 46 pages still over 2 MB need content changes, listed on elastic/docs-eng-team#1183.

Verify

dotnet test --project tests/Elastic.ApiExplorer.Tests
# HtmlWhitespaceTests: indentation, pre/script/textarea/style, closing tags that only look like one,
# attribute values, non-breaking space, a stray '<', an apostrophe in an unquoted value, a 70,000-row page
# OpenApiGeneratorMarkdownEmissionTests.Generate_WritesPagesWithoutTemplateIndentation

Check on the preview

🤖 Generated with Claude Code

@Mpdreamz Mpdreamz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

55 seconds not worth it IMO.

Let's wait for the components/new layouts to land and then re-focus on this?

@akira28
akira28 force-pushed the feature/api-webmarkupmin branch from 5a23291 to d155b4a Compare November 19, 2026 15:33
@akira28 akira28 changed the title Minify API pages with WebMarkupMin before writing them Drop template indentation from API pages before writing them Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4959/

@akira28

akira28 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@Mpdreamz agreed, and the minifier is gone. This PR now drops template indentation with a single pass over each page (HtmlWhitespace.Collapse), with no dependency. Docs builds, alternated with #4956: 65 s and 68 s against 59 s and 68 s, so the build time is unchanged. Pages over 2 MB go from 58 to 46, against 41 with the minifier. I first tried a regex: it doubled the build and once timed out on the largest pages. The single pass takes 2.2 s across all 7,243 pages, and the parsed output matches #4956 on every page compared.

@akira28
akira28 force-pushed the feature/api-webmarkupmin branch from bd6f0e8 to f3e6c46 Compare November 30, 2026 11:37
@akira28
akira28 force-pushed the feature/api-webmarkupmin branch from f3e6c46 to e226a61 Compare November 30, 2026 12:01
@akira28
akira28 force-pushed the feature/api-webmarkupmin branch from e226a61 to eb11e88 Compare November 30, 2026 12:15
@akira28
akira28 force-pushed the feature/api-webmarkupmin branch from eb11e88 to 99564f6 Compare November 30, 2026 12:22
akira28 and others added 7 commits November 30, 2026 13:48
After the sidebar and row changes, 58 API pages are still over
Googlebot's 2 MB limit, many only just. Each API page is now rendered in
memory, and `HtmlWhitespace.Collapse` turns every whitespace run in text
that holds a line break into one line break before the page is written.
Tags, comments and raw-text elements are kept as they are.

It is a single pass, not a regex. A regex over the whole page took about
25 s across all API pages, did not scale across threads, and ran past
its match timeout on the largest pages, failing their whole API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A raw-text element now ends only at its own closing tag: the name
followed by whitespace, '/' or '>', so `</script-example>` does not close
a script. Inside a `pre`, tags are skipped whole, so a `</pre>` in an
attribute value does not end it. `MemoryFileSystemStream` decodes its
buffer in place instead of copying the page twice. A generator test
checks that written rows lose their indentation and keep
`hidden="until-found"`, and the large-page test checks output, not time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inside a `pre`, a comment went through the tag scan, so a quote after an
`=` in it paired with a later attribute's quote and hid the `</pre>`. The
rest of the page was then left uncollapsed. Comments now end at `-->`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inside a `pre`, a `textarea`, `script` or `style` holds raw text, so a
`<!--` in it is not a comment. Read as one with no `-->`, it left the
rest of the page uncollapsed. A nested raw-text element now ends at its
own closing tag before comments are looked for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each `pre` nested in a `pre` was a recursive call, so deep enough nesting
overflowed the stack and ended the build with no error to catch. A `pre`
now counts its nested `pre` elements in a loop. Only a `textarea`,
`script` or `style` inside it is scanned by a call, and raw text holds
no elements, so that goes one level deep at most.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
API pages moved from api/doc/<key> to api/<key> on main. The test's
attribute example uses data-tooltip, now that tippy.js is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active deployments
docs-preview — 0a3244da Deployed Nov 30, 2026 by github-actions[bot]
assembler-preview — 0a3244da Deployed Nov 30, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants