File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ -- Convert.hs
2+
3+ module Convert where
4+
5+ import qualified Markup
6+ import qualified Html
7+
8+ convert :: Html. Title -> Markup. Document -> Html. Html
9+ convert title = Html. html_ title . foldMap convertStructure
10+
11+ convertStructure :: Markup. Structure -> Html. Structure
12+ convertStructure structure =
13+ case structure of
14+ Markup. Heading n txt ->
15+ Html. h_ n txt
16+
17+ Markup. Paragraph p ->
18+ Html. p_ p
19+
20+ Markup. UnorderedList list ->
21+ Html. ul_ $ map Html. p_ list
22+
23+ Markup. OrderedList list ->
24+ Html. ol_ $ map Html. p_ list
25+
26+ Markup. CodeBlock list ->
27+ Html. code_ (unlines list)
Original file line number Diff line number Diff line change @@ -5,12 +5,11 @@ module Html
55 , Title
66 , Structure
77 , html_
8- , h1_
8+ , h_
99 , p_
1010 , ul_
1111 , ol_
1212 , code_
13- , append_
1413 , render
1514 )
1615 where
Original file line number Diff line number Diff line change 22
33module Html.Internal where
44
5+ import Numeric.Natural
6+
57-- * Types
68
79newtype Html
@@ -27,8 +29,8 @@ html_ title content =
2729p_ :: String -> Structure
2830p_ = Structure . el " p" . escape
2931
30- h1_ :: String -> Structure
31- h1_ = Structure . el " h1 " . escape
32+ h_ :: Natural -> String -> Structure
33+ h_ n = Structure . el ( " h " <> show n) . escape
3234
3335ul_ :: [Structure ] -> Structure
3436ul_ =
4143code_ :: String -> Structure
4244code_ = Structure . el " pre" . escape
4345
44- append_ :: Structure -> Structure -> Structure
45- append_ c1 c2 =
46- Structure (getStructureString c1 <> getStructureString c2)
46+ instance Semigroup Structure where
47+ (<>) c1 c2 =
48+ Structure (getStructureString c1 <> getStructureString c2)
49+
50+ instance Monoid Structure where
51+ mempty = Structure " "
4752
4853-- * Render
4954
Original file line number Diff line number Diff line change @@ -9,10 +9,7 @@ myhtml :: Html
99myhtml =
1010 html_
1111 " My title"
12- ( append_
13- (h1_ " Heading" )
14- ( append_
15- (p_ " Paragraph #1" )
16- (p_ " Paragraph #2" )
17- )
12+ ( h_ 1 " Heading"
13+ <> p_ " Paragraph #1"
14+ <> p_ " Paragraph #2"
1815 )
You can’t perform that action at this time.
0 commit comments