]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Formatter.hs
Implemented inline images and framed images
[Rakka.git] / Rakka / Wiki / Formatter.hs
index 95dd9ffb021a8f55e40653c0b5208336202dd465..7a7efce40bd4e8c010d308cae1ab2e9617e61da8 100644 (file)
@@ -44,11 +44,32 @@ formatBlock
          Paragraph inlines
              -> formatParagraph -< (baseURI, inlines)
 
+         Div attrs contents
+             -> formatElem "div" -< (baseURI, attrs, contents)
+    where
+      formatElem :: (ArrowXml a, ArrowChoice a) =>
+                    String
+                 -> a (URI, [Attribute], [BlockElement]) XmlTree
+      formatElem name
+          = proc (baseURI, attrs, contents)
+          -> ( eelem name
+               += ( arrL (fst . snd)
+                       >>>
+                       attrFromPair
+                  )
+               += ( (arr fst &&& arrL (snd . snd))
+                    >>>
+                    formatBlock
+                  )
+             ) -< (baseURI, (attrs, contents))
+
 
 formatHeading :: ArrowXml a => a (Int, String) XmlTree
 formatHeading 
     = proc (level, text)
-    -> selem ("h" ++ show level) [txt text] -<< ()
+    -> mkelem ("h" ++ show level)
+       [ sattr "id" text ]
+       [ txt text        ] -<< ()
 
 
 formatListElement :: (ArrowXml a, ArrowChoice a) => a (URI, ListElement) XmlTree
@@ -134,25 +155,48 @@ formatInline
          Text text
              -> mkText -< text
 
-         Italic inlines
-             -> ( eelem "i"
-                  += ( (arr fst &&& arrL snd)
-                       >>>
-                       formatInline
-                     )
-                ) -< (baseURI, inlines)
+         Italic contents
+             -> formatElem "i" -< (baseURI, [], contents)
 
-         Bold inlines
-             -> ( eelem "b"
-                  += ( (arr fst &&& arrL snd)
-                       >>>
-                       formatInline
-                     )
-                ) -< (baseURI, inlines)
+         Bold contents
+             -> formatElem "b" -< (baseURI, [], contents)
 
          link@(PageLink _ _ _)
              -> formatPageLink -< (baseURI, link)
 
+         LineBreak attrs
+             -> formatElem "br" -< (baseURI, attrs, [])
+
+         Span attrs contents
+             -> formatElem "span" -< (baseURI, attrs, contents)
+
+         Image attrs
+             -> formatElem "img" -< (baseURI, attrs, [])
+
+         Anchor attrs contents
+             -> formatElem "a" -< (baseURI, attrs, contents)
+    where
+      formatElem :: (ArrowXml a, ArrowChoice a) =>
+                    String
+                 -> a (URI, [Attribute], [InlineElement]) XmlTree
+      formatElem name
+          = proc (baseURI, attrs, contents)
+          -> ( eelem name
+               += ( arrL (fst . snd)
+                       >>>
+                       attrFromPair
+                  )
+               += ( (arr fst &&& arrL (snd . snd))
+                    >>>
+                    formatInline
+                  )
+             ) -< (baseURI, (attrs, contents))
+
+
+attrFromPair :: (ArrowXml a) => a (String, String) XmlTree
+attrFromPair = proc (name, value)
+             -> attr name (txt value) -<< ()
+
 
 formatPageLink :: (ArrowXml a) => a (URI, InlineElement) XmlTree
 formatPageLink