-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: traverse state for manuals & html
- Loading branch information
1 parent
a02f17f
commit eaf9786
Showing
5 changed files
with
242 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Verso.Output.Html | ||
|
||
|
||
|
||
namespace Verso.Genre.Manual.Html | ||
open Verso.Output Html | ||
|
||
def titlePage (title : Html) (authors : List String) : Html := {{ | ||
<h1>{{title}}</h1> | ||
<div class="authors"> | ||
{{authors.toArray.map ({{ <span class="author">{{Coe.coe ·}}</span> }})}} | ||
</div> | ||
}} | ||
|
||
def page (textTitle : String) (contents : Html) : Html := {{ | ||
<html> | ||
<head> | ||
<title>{{textTitle}}</title> | ||
</head> | ||
<body> | ||
{{contents}} | ||
</body> | ||
</html> | ||
}} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Lean | ||
import Verso.Method | ||
|
||
namespace Verso.Genre.Manual | ||
open Verso.Method | ||
|
||
structure Slug where | ||
toString : String | ||
deriving BEq, Hashable, DecidableEq, Ord | ||
|
||
namespace Slug | ||
|
||
instance : LT Slug where | ||
lt := (·.toString < ·.toString) | ||
|
||
instance : DecidableRel (@LT.lt Slug _) := fun s1 s2 => | ||
if h : s1.toString < s2.toString then .isTrue h else .isFalse h | ||
|
||
instance : LE Slug where | ||
le s1 s2 := s1 = s2 ∨ s1 < s2 | ||
|
||
instance : DecidableRel (@LE.le Slug _) := fun s1 s2 => | ||
if h : s1 = s2 then .isTrue (.inl h) | ||
else if h' : s1.toString < s2.toString then .isTrue (.inr h') | ||
else .isFalse <| by intro nope; cases nope <;> contradiction | ||
|
||
instance : Coe String Slug where | ||
coe := (⟨·⟩) | ||
|
||
|
||
defmethod String.sluggify (str : String) : Slug := Id.run do | ||
let mut s := "" | ||
for c in str.data do | ||
if c.isAlpha then | ||
s := s.push c.toLower | ||
else if c.isDigit then | ||
s := s.push c | ||
else if c == ' ' || c == '-' then | ||
s := s.push '-' | ||
⟨s⟩ | ||
|
||
partial def unique (used : Lean.HashSet Slug) (slug : Slug) : Slug := | ||
if !(used.contains slug) then slug | ||
else | ||
let rec attempt (i : Nat) := | ||
let slug' := s!"{slug.toString}{i}" | ||
if !(used.contains slug') then slug' | ||
else attempt (i + 1) | ||
attempt 1 |
This file contains 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