From 73b5f3de63a1fda7b50bf6938a632e8e604d231c Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 2 Oct 2026 11:22:02 +0800 Subject: [PATCH] Wrap a long identifier, and add the rendered page to the audit A doc comment names an item by its full path, as in `NoiseTemperature::from_noise_figure_db`. A path has no space in it, so the column could shrink and the word could not, and the interface page of a crate scrolled sideways on a phone. The body of a document now breaks a word rather than overflow. The audit that renders every route now covers the whole interface: 744 combinations, being ninety-three routes in both languages and both themes at two widths, and it passes. It reports four things, which are the four ways a page has failed here before: a page that does not load, a page with almost no text, a page that scrolls sideways, and a formula that loses a letter or a digit. Two mistakes of the audit itself are fixed rather than worked around. It awaited a `Runtime.evaluate` that called `location.reload`. Such a call destroys its own execution context, so the reply never arrives, the promise never settles and the run hangs until the environment kills it. The preferences are now set once per language on a page that stays put, and each route is reached by an ordinary navigation. It gave the browser a function whose comment contained a backtick. The backtick closed the template literal that held the function, so the script did not parse at all. The formula comparison now treats a command name as notation, as it already did for the operators: \Delta draws a Greek letter and \sqrt a radical sign, so neither is drawn as the letters of its own name. --- frontend/src/app.css | 7 +++++++ tests/formula_rendering.rs | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/frontend/src/app.css b/frontend/src/app.css index 2111085..8221411 100644 --- a/frontend/src/app.css +++ b/frontend/src/app.css @@ -863,6 +863,13 @@ button.ghost:hover:not(:disabled) { .doc-body { min-width: 0; + /* + * A doc comment names items by their full path, as in + * `NoiseTemperature::from_noise_figure_db`, and a path has no space in it + * to break at. Left alone it makes the page scroll sideways on a phone, + * because the column can shrink but the word cannot. + */ + overflow-wrap: anywhere; } .doc-body h1, diff --git a/tests/formula_rendering.rs b/tests/formula_rendering.rs index a8853a0..97c0c9e 100644 --- a/tests/formula_rendering.rs +++ b/tests/formula_rendering.rs @@ -20,9 +20,12 @@ //! page, because the layout says what they said. A number or a name has no //! such excuse, so a missing one is a defect. //! -//! `sqrt` is notation of the same kind: it is drawn as the radical sign, so -//! its letters are gone by design and are not missed. Every other function -//! name is drawn as its own letters, as in `sin` and `ln`. +//! A LaTeX command is notation of the same kind. `\sqrt` is drawn as the +//! radical sign and `\Delta` as the Greek letter, so their letters are gone +//! by design and are not missed. A command whose name is its own glyph, such +//! as `\ln`, is drawn as those letters, so stripping every command only +//! makes this check less strict about a function name and never hides a lost +//! number. use apsis_book::docs::document::Language; @@ -53,6 +56,28 @@ fn visible(html: &str) -> String { out } +/// Returns the text with the notation words removed. +/// +/// A formula is written either as LaTeX, where a command is `\sqrt`, or as +/// plain notation, where the same root is the bare word `sqrt`. Both are +/// notation and neither is drawn as those letters. +fn strip_commands(source: &str) -> String { + let source = source.replace("sqrt", ""); + let mut out = String::with_capacity(source.len()); + let mut characters = source.chars().peekable(); + while let Some(character) = characters.next() { + if character == '\\' { + // A command runs to the first character that is not a letter. + while characters.peek().is_some_and(|c| c.is_alphabetic()) { + characters.next(); + } + continue; + } + out.push(character); + } + out +} + /// Returns the formula sources of one document, in order. fn formula_blocks(html: &str) -> Vec { let mut found = Vec::new(); @@ -80,10 +105,9 @@ fn every_formula_shows_every_character_it_was_written_with() { checked += 1; // The source as written, without the spaces that only set it // out on the page. - // `sqrt` is drawn as the radical sign, so its letters are - // notation of the same kind as the operators. - let written: String = source - .replace("sqrt", "") + // A command name is notation: what it draws is a sign or a + // Greek letter, not the letters of its name. + let written: String = strip_commands(&source) .chars() .filter(|c| c.is_alphanumeric()) .collect();