X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FFormatter.hs;h=7a6bde3bc81c631573bac749f5b933f504e2e281;hb=2ad43b49ecc25bdf87dd19037fd63c12428992ae;hp=8d219d2a8e39b19b3a77893ce60ca99cb01db8a7;hpb=87e8b02490f9ca337c1a25de4454d4ad6d1492c6;p=Rakka.git diff --git a/Rakka/Wiki/Formatter.hs b/Rakka/Wiki/Formatter.hs index 8d219d2..7a6bde3 100644 --- a/Rakka/Wiki/Formatter.hs +++ b/Rakka/Wiki/Formatter.hs @@ -28,6 +28,18 @@ formatBlock -> case block of Heading level text -> formatHeading -< (level, text) + + HorizontalLine + -> eelem "hr" -< () + + List list + -> formatListElement -< (baseURI, list) + + DefinitionList list + -> formatDefinitionList -< (baseURI, list) + + Preformatted inlines + -> formatPreformatted -< (baseURI, inlines) Paragraph inlines -> formatParagraph -< (baseURI, inlines) @@ -39,6 +51,73 @@ formatHeading -> selem ("h" ++ show level) [txt text] -<< () +formatListElement :: (ArrowXml a, ArrowChoice a) => a (URI, ListElement) XmlTree +formatListElement + = proc (baseURI, list) + -> let tag = case listType list of + Bullet -> "ul" + Numbered -> "ol" + in + ( eelem tag + += ( (constA baseURI &&& constL (listItems list)) + >>> + formatListItem + ) + ) -<< () + where + formatListItem :: (ArrowXml a, ArrowChoice a) => a (URI, ListItem) XmlTree + formatListItem + = proc (baseURI, item) + -> eelem "li" + += ( (arr fst &&& arrL snd) + >>> + formatListItem' + ) -< (baseURI, item) + + formatListItem' :: (ArrowXml a, ArrowChoice a) => a (URI, Either ListElement InlineElement) XmlTree + formatListItem' + = proc (baseURI, x) + -> case x of + Left nestedList -> formatListElement -< (baseURI, nestedList) + Right inline -> formatInline -< (baseURI, inline ) + + +formatDefinitionList :: (ArrowXml a, ArrowChoice a) => a (URI, [Definition]) XmlTree +formatDefinitionList + = proc (baseURI, list) + -> ( eelem "dl" + += ( (arr fst &&& arrL snd) + >>> + formatDefinition + ) + ) -< (baseURI, list) + where + formatDefinition :: (ArrowXml a, ArrowChoice a) => a (URI, Definition) XmlTree + formatDefinition + = proc (baseURI, def) + -> ( eelem "dt" + += ( (arr fst &&& arrL (defTerm . snd)) + >>> + formatInline + ) + <+> + eelem "dd" + += ( (arr fst &&& arrL (defDesc . snd)) + >>> + formatInline + ) + ) -< (baseURI, def) + + +formatPreformatted :: (ArrowXml a, ArrowChoice a) => a (URI, [InlineElement]) XmlTree +formatPreformatted + = eelem "pre" + += ( (arr fst &&& arrL snd) + >>> + formatInline + ) + + formatParagraph :: (ArrowXml a, ArrowChoice a) => a (URI, [InlineElement]) XmlTree formatParagraph = eelem "p" @@ -55,9 +134,35 @@ formatInline Text text -> mkText -< text + Italic inlines + -> ( eelem "i" + += ( (arr fst &&& arrL snd) + >>> + formatInline + ) + ) -< (baseURI, inlines) + + Bold inlines + -> ( eelem "b" + += ( (arr fst &&& arrL snd) + >>> + formatInline + ) + ) -< (baseURI, inlines) + link@(PageLink _ _ _) -> formatPageLink -< (baseURI, link) + LineBreak attrs + -> ( eelem "br" + += (arrL id >>> attrFromPair) + ) -< attrs + + +attrFromPair :: (ArrowXml a) => a (String, String) XmlTree +attrFromPair = proc (name, value) + -> attr name (txt value) -<< () + formatPageLink :: (ArrowXml a) => a (URI, InlineElement) XmlTree formatPageLink