]> ruin.nu Git - yawbih.git/blobdiff - Wiki.hs
more
[yawbih.git] / Wiki.hs
diff --git a/Wiki.hs b/Wiki.hs
index 64c46028bdcd8dd51d204037457e5bba4302866b..0b9e337da4bd7e50f7ebb266c88ca2d9c7bf6c28 100644 (file)
--- a/Wiki.hs
+++ b/Wiki.hs
@@ -2,7 +2,7 @@ module Wiki (
        Backend (getCurrent,getList,get,setCurrent,update)
        ,PGB
        ,createPGB
-       ,Markup (Text, Paragraph, Link)
+       ,Markup (Text, Paragraph, Link, Bold)
        ,Document
        ,wikiParser
 
@@ -20,7 +20,7 @@ class Backend a where
        getList :: a -> String -> IO [(String, String, String, String)]
 
        --Keyword -> id -> Full text
-       get :: a -> String -> String -> IO String
+       get :: a -> String -> String -> IO (Maybe String)
 
        --Keyword -> id -> ()
        setCurrent :: a -> String -> String -> IO Bool
@@ -31,15 +31,17 @@ class Backend a where
 data Markup = Text String
        | Paragraph 
        | Link String String
+       | Bold [Markup]
 
 type Document = [Markup]
 
 wikiParser :: GenParser Char st Document       
 wikiParser = do 
        s <- (try (pPara) 
-               <|> pOneEol 
+               <|> pSpace 
                <|> try (pLinkLong)
-               <|> pLink
+               <|> try (pLink)
+               <|> pOtherChar
                <|> pText)
        ss <- (wikiParser <|> return [])
        return (s:ss)
@@ -49,8 +51,9 @@ pPara = do
        pEol
        return (Paragraph)
 
-pOneEol = do
-       pEol
+
+pSpace = do
+       space 
        return (Text " ")
 
 pEol = char '\n' <|> do
@@ -59,21 +62,31 @@ pEol = char '\n' <|> do
 
 pLinkLong = do
        string "[["
-       l <- many1 $ noneOf ['|','[',']']
+       l <- many1 $ noneOf ['|']
        char '|'
-       d <- many1 $ noneOf ['|','[',']'] 
+       d <- many1 $ noneOf "]" 
        string "]]"
        return (Link l d)
+
+pBold = do
+       string "'''"
+       s <- wikiParser
+       return (Bold s)
+
 pLink = do
        string "[["
-       l <- many1 $ noneOf ['|','[',']']
+       l <- many1 $ noneOf "]"
        string "]]"
        return (Link l l)
+pOtherChar = do
+       c <- oneOf ",;.:!?[]()\'\"=-%$£<>/\\|"
+       return (Text (c:[]))
 
 pText = do
-       t <- many1 (noneOf ['\n','\r','[',']'])
+       t <- many1 alphaNum--(noneOf ['\n','\r','[',']'])
        return (Text t)
 
+
 newtype PGB = PGB DBService
 
 createPGB :: String -> String -> String -> String -> IO PGB
@@ -94,7 +107,11 @@ instance Backend PGB where
                list <- selectReturnTuples db $ "SELECT id, timestamp, author, comment from fulltexts WHERE keyword = "++tov key
                return $ map (\[id,date,author,comment] -> (id,date,author,comment)) list
 
-       get (PGB db) key id = return ""
+       get (PGB db) key id = do
+               list <- selectReturnTuples db $ "SELECT fulltext from fulltexts WHERE id = "++tov id    
+               case list of
+                       [s]:_ -> return (Just s)
+                       _ -> return Nothing
 
        setCurrent (PGB db) key id = do
                full <- selectReturnTuples db $ "SELECT keyword FROM fulltexts WHERE keyword="++tov key++" AND id='"++id++"'"