X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FWiki%2FParser.hs;h=6c5d20722c89f8243b8accc45fe193d771b33f8b;hb=4e8a07033b0b0ea0961bffb3bab0b6fc9c21afba;hp=313521c23cf89971862f4091657d9ef22bef5348;hpb=f832f12703d807f5fc3350dc71d8624ffc5b97a5;p=Rakka.git diff --git a/Rakka/Wiki/Parser.hs b/Rakka/Wiki/Parser.hs index 313521c..6c5d207 100644 --- a/Rakka/Wiki/Parser.hs +++ b/Rakka/Wiki/Parser.hs @@ -5,6 +5,7 @@ module Rakka.Wiki.Parser where import Data.Maybe +import Network.URI import Rakka.Wiki import Text.ParserCombinators.Parsec @@ -232,7 +233,11 @@ blockCmd cmdTypeOf , bCmdAttributes = tagAttrs , bCmdContents = xs } - _ -> pzero + + Just InlineCommandType + -> pzero + + _ -> return $ undefinedCmdErr tagName ) <|> (try $ do (tagName, tagAttrs) <- emptyTag @@ -243,20 +248,35 @@ blockCmd cmdTypeOf , bCmdAttributes = tagAttrs , bCmdContents = [] } - _ -> pzero + + Just InlineCommandType + -> pzero + + _ -> return $ undefinedCmdErr tagName ) "block command" where contents :: Parser [BlockElement] - contents = do x <- try $ blockElement cmdTypeOf + contents = do x <- blockElement cmdTypeOf xs <- contents return (x:xs) <|> + (newline >> contents) + <|> (comment >> contents) <|> return [] + undefinedCmdErr :: String -> BlockElement + undefinedCmdErr name + = Div [("class", "error")] + [ Paragraph [Text ("The command `" ++ name ++ "' is not defined. " ++ + "Ensure that you haven't mistyped and the module " ++ + "providing the command is actually loaded.") + ] + ] + inlineElement :: CommandTypeOf -> Parser InlineElement inlineElement cmdTypeOf @@ -265,6 +285,7 @@ inlineElement cmdTypeOf , apostrophes cmdTypeOf , text , pageLink + , extLink , inlineCmd cmdTypeOf ] @@ -343,6 +364,20 @@ pageLink = do try (string "[[") "page link" +extLink :: Parser InlineElement +extLink = do char '[' + uriStr <- many1 (noneOf " \t]") + skipMany (oneOf " \t") + text <- option Nothing + (many1 (noneOf "]") >>= return . Just) + + case parseURI uriStr of + Just uri -> char ']' >> return (ExternalLink uri text) + Nothing -> pzero "absolute URI" + + "external link" + + inlineCmd :: CommandTypeOf -> Parser InlineElement inlineCmd cmdTypeOf = (try $ do (tagName, tagAttrs) <- openTag