X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Wiki.hs;h=7d337c9f679b3b14ce01e1bf6716864a3390fb6d;hb=cfd9357931f136f52df2becd0af605111e102234;hp=ab89fff9de0e8c6a9a6e6bd834b67fd589d26c81;hpb=69ecfedf2b7e27f50f7c2cedf534a036fe16907e;p=yawbih.git diff --git a/Wiki.hs b/Wiki.hs index ab89fff..7d337c9 100644 --- a/Wiki.hs +++ b/Wiki.hs @@ -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 @@ -37,8 +37,10 @@ type Document = [Markup] wikiParser :: GenParser Char st Document wikiParser = do s <- (try (pPara) - <|> pOneEol - <|> pLinkLong + <|> pSpace + <|> try (pLinkLong) + <|> try (pLink) + <|> pOtherChar <|> pText) ss <- (wikiParser <|> return []) return (s:ss) @@ -48,8 +50,9 @@ pPara = do pEol return (Paragraph) -pOneEol = do - pEol + +pSpace = do + space return (Text " ") pEol = char '\n' <|> do @@ -58,15 +61,25 @@ 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) +pLink = do + string "[[" + 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 @@ -87,7 +100,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++"'"