Skip to content

Commit a6000da

Browse files
committed
fix: improve error name rendering in narrower viewports
This commit drops error name prefixes from the table and sidebar and allows hyphenation at reasonable split points.
1 parent 0c92d66 commit a6000da

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

Manual/ErrorExplanations.lean

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ inline_extension Inline.errorExplanationLink (errorName : Name) where
3838
logError s!"Could not find external tag for error explanation '{name}' corresponding to ID '{id}'"
3939
content.mapM go
4040

41+
/- Renders the suffix of an error explanation, allowing line breaks before capital letters. -/
42+
inline_extension Inline.errorExplanationShortName (errorName : Name) where
43+
data := toJson (getBreakableSuffix errorName)
44+
traverse := fun _ _ _ => pure none
45+
extraCss := [".error-explanation-short-name { hyphenate-character: ''; }"]
46+
toTeX := none
47+
toHtml := some fun _go _id info _content =>
48+
open Verso.Output Html in do
49+
let .ok (some errorName) := fromJson? (α := Option String) info
50+
| HtmlT.logError "Invalid data for explanation name element"
51+
pure .empty
52+
let html := {{ <code class="error-explanation-short-name">{{errorName}}</code> }}
53+
return html
54+
4155
@[block_role_expander error_explanation_table]
4256
def error_explanation_table : BlockRoleExpander
4357
| #[], #[] => do
@@ -49,11 +63,10 @@ def error_explanation_table : BlockRoleExpander
4963
let headers ← #["Name", "Summary", "Severity", "Since"]
5064
|>.mapM fun s => ``(Verso.Doc.Block.para #[Doc.Inline.text $(quote s)])
5165
let vals ← entries.flatMapM fun (name, explan) => do
52-
let sev := quote <|
53-
if explan.metadata.severity == .warning then "Warning" else "Error"
66+
let sev := quote <| if explan.metadata.severity == .warning then "Warning" else "Error"
5467
let sev ← ``(Doc.Inline.text $sev)
55-
let nameStr := toString name
56-
let nameLink ← ``(Doc.Inline.other (Inline.errorExplanationLink $(quote name)) #[Doc.Inline.code $(quote nameStr)])
68+
let nameLink ← ``(Doc.Inline.other (Inline.errorExplanationLink $(quote name))
69+
#[Doc.Inline.other (Inline.errorExplanationShortName $(quote name)) #[]])
5770
let summary ← ``(Doc.Inline.text $(quote explan.metadata.summary))
5871
let since ← ``(Doc.Inline.text $(quote explan.metadata.sinceVersion))
5972
#[nameLink, summary, sev, since]
@@ -72,7 +85,8 @@ htmlToc := false
7285
%%%
7386

7487
This section provides explanations of errors and warnings that may be generated
75-
by Lean when processing a source file.
88+
by Lean when processing a source file. All error names listed below have the
89+
`lean` package prefix.
7690

7791
{error_explanation_table}
7892

Manual/Meta/ErrorExplanation.lean

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,22 @@ def explanation : PartCommand
678678
addExplanationBlocksFor config.name.getId
679679
| _ => Lean.Elab.throwUnsupportedSyntax
680680

681+
/--
682+
Returns the suffix of `name` as a string containing soft-hyphen characters at reasonable split points.
683+
-/
684+
def getBreakableSuffix (name : Name) : Option String := do
685+
let suffix ← match name with
686+
| .str _ s => s
687+
| .num _ n => toString n
688+
| .anonymous => none
689+
let breakableHtml := softHyphenateIdentifiers.rwText (.text false suffix)
690+
htmlText breakableHtml
691+
where
692+
htmlText : Verso.Output.Html → String
693+
| .text _ txt => txt
694+
| .seq elts => elts.foldl (· ++ htmlText ·) ""
695+
| .tag _nm _attrs children => htmlText children
696+
681697
open Verso Doc Elab ArgParse in
682698
open Lean in
683699
/-- Renders all error explanations as parts of the current page. -/
@@ -690,10 +706,12 @@ def make_explanations : PartCommand
690706
let titleBits := #[← ``(Inline.other
691707
(Inline.errorExplanation $(quote name) $(quote explan.metadata.summary))
692708
#[Inline.code $(quote titleString)])]
709+
let some shortTitleString := getBreakableSuffix name
710+
| throwError m!"Found invalid explanation name `{name}` when generating explanations section"
693711
PartElabM.push {
694712
titleSyntax := quote (k := `str) titleString,
695713
expandedTitle := some (titleString, titleBits),
696-
metadata := none,
714+
metadata := some (← `({ shortTitle := $(quote shortTitleString) })),
697715
blocks := #[],
698716
priorParts := #[]
699717
}

0 commit comments

Comments
 (0)