Skip to content

Commit 536cd09

Browse files
feat: allow markup in tutorial summaries (#703)
1 parent d46ba7b commit 536cd09

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

examples/tutorial-examples/TutorialExample/Data.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open Verso.Genre.Manual.InlineLean
1111
#doc (Tutorial) "Inductive Types" =>
1212
%%%
1313
slug := "inductive-types"
14-
summary := "describes inductive types"
14+
summary := inlines!"describes inductive types"
1515
exampleStyle := .inlineLean `Data
1616
%%%
1717

examples/tutorial-examples/TutorialExample/HashMap.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open Verso.Genre.Manual InlineLean
1414
#doc (Tutorial) "Using `Std.HashMap`" =>
1515
%%%
1616
slug := "hashmap"
17-
summary := "describes hash maps"
17+
summary := inlines!"describes hash maps"
1818
exampleStyle := .inlineLean `HashMap
1919
%%%
2020

examples/tutorial-examples/TutorialExample/RCases.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open Verso.Genre.Manual InlineLean
1212
#doc (Tutorial) "RCases" =>
1313
%%%
1414
slug := "rcases"
15-
summary := "is a tactic for case analysis"
15+
summary := inlines!"is a tactic for case analysis"
1616
exampleStyle := .inlineLean `RCases
1717
%%%
1818

src/verso-manual/VersoManual/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ instance : TeX.GenreTeX Manual (ReaderT ExtensionImpls IO) where
14421442
impl goI goB id b.data content
14431443
inline go i content := do
14441444
let some id := i.id
1445-
| panic! "Inline {i.name} wasn't assigned an ID during traversal"
1445+
| panic! s!"Inline {i.name} wasn't assigned an ID during traversal"
14461446
let some descr := (← readThe ExtensionImpls).getInline? i.name
14471447
| panic! s!"Unknown inline {i.name} while rendering.\n\nKnown inlines: {(← readThe ExtensionImpls).inlineDescrs.toArray |>.map (·.fst) |>.qsort (·.toString < ·.toString)}"
14481448
let some impl := descr.toTeX
@@ -1509,7 +1509,7 @@ instance : Html.GenreHtml Manual (ReaderT AllRemotes (ReaderT ExtensionImpls IO)
15091509

15101510
inline go i content := do
15111511
let some id := i.id
1512-
| panic! "Inline {i.name} wasn't assigned an ID during traversal"
1512+
| panic! s!"Inline {i.name} wasn't assigned an ID during traversal"
15131513
let some descr := (← readThe ExtensionImpls).getInline? i.name
15141514
| panic! s!"Unknown inline {i.name} with data {i.data} while rendering HTML.\n\nKnown inlines: {(← readThe ExtensionImpls).inlineDescrs.toArray |>.map (·.fst) |>.qsort (·.toString < ·.toString)}"
15151515
let some impl := descr.toHtml

src/verso-tutorial/VersoTutorial.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ def toSite (tuts : Tutorials) : EmitM Blog.Site := do
467467
let some m := tut.metadata
468468
| return none
469469
return some {
470-
term := #[.link (← tut.title.mapM inlineToPage) s!"./{m.slug}/"],
471-
desc := tut.metadata.map (.para #[.text <| ·.summary]) |>.toArray
470+
term := #[.link (← tut.title.mapM inlineToPage) s!"./{m.slug}/g"],
471+
desc := (← tut.metadata.mapM ((Block.para #[·]) <$> inlineToPage ·.summary)).toArray
472472
}
473473
return { t with
474474
metadata := none,

src/verso-tutorial/VersoTutorial/Basic.lean

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ inductive ExampleCodeStyle where
3434
The example code should be extracted to a Lean project from the tutorial.
3535
-/
3636
| inlineLean (moduleName : Lean.Name) (toolchain := defaultToolchain) (liveProject := some defaultLive)
37-
deriving BEq, DecidableEq, Inhabited, Repr, ToJson, FromJson
37+
deriving BEq, Hashable, DecidableEq, Inhabited, Repr, ToJson, FromJson
3838

3939
open Manual (Tag InternalId) in
4040
/-- Metadata on tutorials. -/
@@ -46,10 +46,10 @@ structure Tutorial.PartMetadata where
4646
/-- The internal unique ID, which is automatically assigned during traversal. -/
4747
id : Option InternalId := none
4848
/-- A summary to show on the overview page. -/
49-
summary : String
49+
summary : Verso.Doc.Inline Manual
5050
/-- How should the code samples in this tutorial be extracted to a downloadable tarball? -/
5151
exampleStyle : ExampleCodeStyle
52-
deriving BEq, DecidableEq, Inhabited, Repr, ToJson, FromJson
52+
deriving BEq, Hashable, Inhabited, Repr, ToJson, FromJson
5353

5454
/--
5555
Information that tracks the current context of traversal for a set of tutorials.
@@ -100,7 +100,7 @@ open Manual (ExtensionImpls)
100100

101101
/-- The metadata to use for a tutorial when the user does not specify any. -/
102102
def defaultMetadata (p : Part Tutorial) : Tutorial.PartMetadata :=
103-
{ slug := p.titleString.sluggify.toString, summary := "", exampleStyle := .inlineLean `Main }
103+
{ slug := p.titleString.sluggify.toString, summary := inlines!"", exampleStyle := .inlineLean `Main }
104104

105105
instance : TraversePart Tutorial where
106106
inPart p ctx :=
@@ -186,6 +186,9 @@ instance : Traverse Tutorial TraverseM where
186186
-- Next, assign a tag, prioritizing user-chosen external IDs
187187
«meta» := { «meta» with tag := ← withReader (TraversePart.inPart part) <| tagPart part «meta» (·.id) (·.tag) savePartXref }
188188

189+
-- Traverse the metadata's description
190+
«meta» := { «meta» with summary := ← withReader (TraversePart.inPart part) <| Genre.traverseInline Manual «meta».summary }
191+
189192
pure <|
190193
if «meta» == startMeta then none
191194
else pure { part with metadata := some «meta» }

src/verso/Verso/Doc/Concrete/InlineString.lean

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ syntax:max (name := inlinesLit) "inlines!" noWs str : term
2424
syntax:max (name := blocksLit) "blocks!" noWs str : term
2525

2626
open Lean Elab Term in
27-
elab_rules : term
27+
elab_rules : term <= ty
28+
| `(inlines!"") => do
29+
elabTerm (← ``(Lean.Doc.Inline.empty)) ty
2830
| `(inlines!%$tk$s) => do
2931
let inls ← stringToInlines s
3032
let gTerm ← `(term|_%$tk)
@@ -33,7 +35,9 @@ elab_rules : term
3335
⟨gTerm, g, .onlyIfDefined, .none⟩
3436
{ highlightDeduplicationTable := .none }
3537
(.init (← `(foo))) <| inls.mapM (elabInline ⟨·⟩)
36-
elabTerm (← ``(Inline.concat #[ $[$tms],* ] )) none
38+
elabTerm (← ``(Inline.concat #[ $[$tms],* ] )) ty
39+
| `(blocks!"") => do
40+
elabTerm (← ``(Lean.Doc.Block.empty)) ty
3741
| `(blocks!%$tk$s) => do
3842
let inls ← stringToBlocks s
3943
let g ← Meta.mkFreshExprMVar (some (.const ``Verso.Doc.Genre []))
@@ -42,7 +46,7 @@ elab_rules : term
4246
⟨gTerm, g, .onlyIfDefined, .none⟩
4347
{ highlightDeduplicationTable := .none }
4448
(.init (← `(foo))) <| inls.mapM (elabBlock ⟨·⟩)
45-
elabTerm (← ``(Block.concat #[ $[$tms],* ] )) none
49+
elabTerm (← ``(Block.concat #[ $[$tms],* ] )) ty
4650

4751

4852
set_option pp.rawOnError true

0 commit comments

Comments
 (0)