Repository navigation
Escape literal names in the API Markdown export - #5042
Conversation
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/5042/ |
The export wrote names from the spec as raw Markdown, so a group titled `HTTP <code> responses` read back as a tag and lost a word. Names now go through `ApiCommonMark.Text`, which escapes only what could start markup. Front-matter titles and descriptions are plain text, read with Markdig. The same converter replaces the regexes in `ApiSeoDescription`, so SEO excerpts keep code spans, escapes and underscores inside words as written. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A trailing `#` in a heading title is escaped so it is not read as a closing sequence, and the link pass skips an escaped `](`. The front-matter title is quoted YAML read as a heading, so `#404` and `1. List roles` survive. An operation's summary stays literal, the catalog excerpt is escaped, and the plain-text converter leaves HTML as written, as the regexes did, so literal placeholders stay and the property index still strips real tags. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3f42887 to
7a2f962
Compare
Plain text is now the text a reader sees: Markdig renders the Markdown to HTML, as an API description is, and `ApiMarkdown.StripHtml` reads it. Real HTML links and blocks keep their text, tags go, and code spans and escapes stay. The converter moves to `ApiMarkdown`, and the property index no longer strips HTML twice. `TextHeading` and `TextLink` write literal names, `Text` escapes a closing `#` itself so authored headings keep theirs, and the link pass counts backslashes before `]`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| private static readonly MarkdownPipeline PlainTextPipeline = new MarkdownPipelineBuilder().Build(); | ||
|
|
||
| /// <summary> | ||
| /// Markdown as the text a reader sees on the page: rendered to HTML, as an API description is, then read for its text. Code spans, | ||
| /// escapes and entities come out as written; emphasis, link targets and tags go, while the text inside HTML blocks and links stays. | ||
| /// </summary> | ||
| internal static string ToPlainText(string markdown) => StripHtml(Markdown.ToHtml(markdown, PlainTextPipeline)); |
There was a problem hiding this comment.
Severity: P3 (Low)
PlainTextPipeline no longer calls DisableHtml(). Because of that, a bare <index> or <target> placeholder in a description is parsed as an inline HTML tag, and StripHtml then drops it. SEO meta descriptions, catalog summaries and front-matter description: values (all built through ApiSeoDescription.Excerpt/FirstLine) now lose those words. For example, Returns <index> when available. becomes Returns when available.. The old regex converter kept the placeholder, and the PR description says it still survives. The test ToPlainText_Html_StaysAsWritten that guarded this case was deleted, not updated. Either restore DisableHtml() and strip real tags only where they are needed, or update the claim and add a test for the new behaviour.
Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.
There was a problem hiding this comment.
Keeping this, by the rule this PR now states: plain text is what the rendered page shows. The page renders a description's raw HTML through ApiDescriptionPipeline and then HtmlSanitizer, which removes an unknown tag such as <index>, so the page does not show it either. A placeholder meant to show belongs in a code span, which keeps it. The PR description does not claim a bare placeholder survives. ToPlainText_Markdown_IsTheTextThePageShows now pins this case in 78b8366.
| /// Markdown as the text a reader sees on the page: rendered to HTML, as an API description is, then read for its text. Code spans, | ||
| /// escapes and entities come out as written; emphasis, link targets and tags go, while the text inside HTML blocks and links stays. | ||
| /// </summary> | ||
| internal static string ToPlainText(string markdown) => StripHtml(Markdown.ToHtml(markdown, PlainTextPipeline)); |
There was a problem hiding this comment.
Severity: P3 (Low)
Preserve Markdown image alt text in plain-text descriptions. Rendering See . to HTML puts the label in an alt attribute, which StripHtml never reads. This drops words from search descriptions and makes an image-only description fall back to generic text.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
There was a problem hiding this comment.
Keeping this, by the same rule: an image shows as a picture, and its alt text is not visible text on the page. Pinned in ToPlainText_Markdown_IsTheTextThePageShows in 78b8366.
A bare `<index>` in a description is raw HTML that the page's sanitizer removes, and an image shows as a picture, so neither reaches plain text. The tests now state that rule next to the cases that keep text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The API Markdown export now writes names from the spec, such as a group titled
HTTP <code> responses, as escaped text. A reader or parser gets them back as written, and front-matter titles and descriptions are plain text.Affects: Content export, API reference, Search
Prompt summary: The author asks to rethink making API group, type and topic pages searchable (elastic/docs-eng-team#1230) after review rounds on #5036 kept finding edge cases. The goal is the cleanest design, not more patches. This PR is the first part: an export that search and other readers can parse without guessing.
Stack: 1 of 2. #5043 builds searchable API pages on it.
Why
ApiCommonMarkwrites names from the spec into headings, link text and paragraphs as raw Markdown. A name such asHTTP <code> responsestherefore reads back as an HTML tag and loses a word. A name with*,_,[or a backtick can turn into emphasis, a link or code. The front-mattertitleis the raw H1 line, and some descriptions are raw Markdown while others are plain text. Every reader of the export, including the downloadable.mdpages and search, has to guess which is which.What
Literal text is escaped
ApiCommonMark.Textescapes only what could start markup where it stands: backslashes, backticks,*, brackets, angle brackets, an underscore at a word boundary, and an&that would read as an entity.max_docsandSnapshot & restorestay as they are. Each export writer that passes a name uses it, throughTextHeadingandTextLink: group, type, topic, structural and operation titles, catalog and overview rows, link text, example and scenario titles, and auth scheme labels. Callers that pass Markdown, such as authored supplemental headings or a link wrapped around a code span, keep the raw path. A literal title ending in#keeps its#, and the link pass skips a]escaped by an odd run of backslashes.Plain-text front matter
ApiMarkdownFrontMatter.Collectreads the H1 and every Markdown description source through one plain-text converter. Sotitle:anddescription:hold what a reader sees, with escapes, code spans and link targets resolved. The title is read as a heading, so1. List roleskeeps its number, and it is written as quoted YAML, like the description. An operation without its own description takes its OpenAPI summary as written.One plain-text converter
ApiMarkdown.ToPlainTextdefines plain text as what a reader sees on the page. Markdig renders the Markdown to HTML, as an API description is rendered, andApiMarkdown.StripHtmlreads its text. Code spans, escapes, entities and underscores inside words come out as written. Emphasis, link targets and tags go, while the text of HTML links and blocks stays. It replaces the eight regexes inApiSeoDescription, so SEO excerpts, front matter and property-search descriptions all read text the same way. The property index no longer strips HTML a second time.Review rules
These settle trade-offs that review findings can pull either way. A finding that breaks one is a bug; one that asks to trade against it is out of scope.
<index>and image alt text do not appear, and plain text drops them too. A placeholder meant to show goes in a code span.Verify
Check on the preview
# Deletes a single Knowledge Base Entry using the \`id\` field, so it reads back as the HTML page shows it, with literal backticks. Production's Markdown turns them into a code span. Front matter has the quoted plain title.#### Dry-run preview of matching rules; set \`force: true\` on the request to execute, an example title kept literal.title.🤖 Generated with Claude Code