feat: support hidden lines in example code blocks#802
Merged
Conversation
Lines in JavaScript/TypeScript example code blocks that begin with `# ` (or consist solely of `#`) are now hidden from rendered documentation, mirroring rustdoc's documentation-test behavior. A leading `##` is an escape for a literal `#`. Hidden lines are removed from the displayed code (both HTML and terminal output) but retained in the HTML copy button so copied snippets remain runnable. Processing is limited to JS/TS code blocks so that other snippets (e.g. shell examples that legitimately begin a line with `#`) are unaffected.
|
|
crowlKats
approved these changes
Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements hideable lines in example code blocks, à la rustdoc's documentation tests.
Closes denoland/deno#21574.
Behavior
Within a JavaScript/TypeScript example code block:
#(hash + space), or consisting solely of#, is hidden from the rendered documentation.##is an escape and renders as a single leading#.renders as:
This lets authors keep boilerplate (imports, setup) runnable in doc tests (
deno test --docalready strips these markers) without cluttering the rendered output.Notes / design choices
data-copyso copied snippets still execute as written.ts,js,tsx,mts, …). Other blocks (e.g. shell snippets that legitimately begin a line with#) are rendered verbatim. Happy to widen/narrow this set if preferred.#!) and private fields (#x, no following space) are left untouched.Tests
Added unit tests for the line-processing helper, the terminal printer, and the HTML renderer. Existing snapshot tests are unaffected.
cargo test,cargo fmt -- --check, andcargo clippy --all-targets -- -D clippy::allall pass.