]> ruin.nu Git - yawbih.git/commitdiff
Latex output
authorMichael Andreen <harv@ruin.nu>
Sun, 6 Feb 2005 11:53:53 +0000 (11:53 +0000)
committerMichael Andreen <harv@ruin.nu>
Sat, 26 Jan 2008 11:33:19 +0000 (12:33 +0100)
Main.hs
Wiki.hs

diff --git a/Main.hs b/Main.hs
index 8dec3829a18d5fe82717ccc98ded344292763635..53ea09d136ceae2f5b56a8de29f2d0f62985e53e 100644 (file)
--- a/Main.hs
+++ b/Main.hs
@@ -56,6 +56,16 @@ showPage db key = do
                                p $ tt $ text $ "Last edited: "++date
                footer db key
 
+showLatex db key = do
+       s <- io $ getCurrent db key 
+       standardQuery key $ do
+               case s of
+                       Nothing -> text "No text added for this keyword"
+                       Just (full, date) -> do
+                               parseLatex full 
+                               p $ tt $ text $ "Last edited: "++date
+               footer db key
+
 parseText full = case parse wikiParser "" full of
        Right n -> toWash n     
        Left e -> do
@@ -63,12 +73,19 @@ parseText full = case parse wikiParser "" full of
                text (show e)
                p $ text full
 
+parseLatex full = case parse wikiParser "" full of
+       Right n -> pre $ text $ toLatex n       
+       Left e -> do
+               text "PARSE ERROR: "
+               text (show e)
+
 footer db key = do
        hr empty
        table $ tr $ do
                td $ submitLink0 (showPage db "itproj3") (text "Back to main page")
                when (e key) $ td $ submitLink0 (editPage db key) (text "Edit this keyword")
                when (e key) $ td $ submitLink0 (listRevs db key) (text "List old versions")
+               when (e key) $ td $ submitLink0 (showLatex db key) (text "Output latex")
                td $ submitLink0 (listKeywords db) (text "List all keywords")
                td $ text "Keyword: " 
                td $ activate (showPage db) textInputField empty
diff --git a/Wiki.hs b/Wiki.hs
index 94f4a5f433000c2a86cbd8eb19cc7ca1f8dffb8d..210708df3d3a100fb50d267f33d1e647604acb37 100644 (file)
--- a/Wiki.hs
+++ b/Wiki.hs
@@ -6,7 +6,8 @@ module Wiki (
        ,FontOp (Bold, Emph, Mono, Underline, Strike)
        ,Document
        ,wikiParser
-       ,htmlOutput
+       ,toHtml
+       ,toLatex
 
 ) where
 
@@ -242,21 +243,44 @@ toHtml [] = []
 toHtml ((Paragraph):xs) = "<p>\n"++toHtml xs
 toHtml ((Text s):xs) = s++toHtml xs
 toHtml ((Link l d):xs) = "<link: "++l++" desc: "++d++">"++toHtml xs
-toHtml ((Font o d):xs) = "<"++fontOp o++">"++toHtml d++"</"++fontOp o++">"++toHtml xs
+toHtml ((Font o d):xs) = "<"++htmlFontOp o++">"++toHtml d++"</"++htmlFontOp o++">"++toHtml xs
 toHtml ((Heading n d):xs) = "\n<h"++show n++">"++toHtml d++"</h"++show n++">\n"++toHtml xs
 toHtml ((Url l):xs) = "<link: "++l++">"++toHtml xs
 toHtml ((Pre s):xs) = "<pre>"++toHtml s++"</pre>"++toHtml xs
-toHtml ((List o l):xs) = "<"++listType o++">\n"++(unlines $ map (\s -> "<li>"++toHtml s++"</li>\n") l) ++ "</"++listType o++">"++toHtml xs
-
-listType True = "ol"
-listType False = "ul"
-
-fontOp Bold = "b"
-fontOp Emph = "em"
-fontOp Mono = "tt"
-fontOp Underline = "u"
-fontOp Strike = "strike"
-
-htmlOutput s = case parse wikiParser "" s of
-                                       Right n -> putStr (toHtml n)
+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