+toHtml ((Pre s):xs) = "<pre>"++toHtml s++"</pre>"++toHtml xs
+toHtml ((List o l):xs) = "<"++htmlListType o++">\n"++(unlines $ map (\s -> "<li>"++toHtml s++"</li>\n") l) ++ "</"++htmlListType o++">"++toHtml xs
+
+htmlFontOp Bold = "b"
+htmlFontOp Emph = "em"
+htmlFontOp Mono = "tt"
+htmlFontOp Underline = "u"
+htmlFontOp Strike = "strike"
+
+htmlListType True = "ol"
+htmlListType False = "ul"
+
+toLatex :: [Markup] -> String
+toLatex [] = []
+toLatex ((Paragraph):xs) = "\n\n"++toLatex xs
+toLatex ((Text s):xs) = s++toLatex xs
+toLatex ((Link l d):xs) = "{\\em "++d++"}"++toLatex xs
+toLatex ((Font o d):xs) = "{\\"++latexFontOp o++" "++toLatex d++"}"++toHtml xs
+toLatex ((Heading n d):xs) = "\n\\"++(unwords $ take (n-1) $ repeat "sub")++"section{"++toLatex d++"}"++"\n\n"++toLatex xs
+toLatex ((Url l):xs) = "{\\bf "++l++"}"++toLatex xs
+toLatex ((Pre s):xs) = "<pre>"++toLatex s++"</pre>"++toLatex xs
+toLatex ((List o l):xs) = "\n\\begin{"++latexListType o++"}\n"++(unlines $ map (\s -> "\\item "++toLatex s++"\n") l) ++ "\\end{"++latexListType o++"}"++toLatex xs
+
+latexFontOp Bold = "bf"
+latexFontOp Emph = "em"
+latexFontOp Mono = "tt"
+latexFontOp Underline = "u"
+latexFontOp Strike = "strike"
+
+latexListType True = "enumeration"
+latexListType False = "itemize"
+
+output s f = case parse wikiParser "" s of
+ Right n -> putStr (f n)
+ Left e -> print e
+
+htmlOutput s = output s toHtml
+latexOutput s = output s toLatex