where
import Data.Maybe
+import Network.URI
import Rakka.Wiki
import Text.ParserCombinators.Parsec
, bCmdAttributes = tagAttrs
, bCmdContents = xs
}
- _ -> pzero
+
+ Just InlineCommandType
+ -> pzero
+
+ _ -> return $ undefinedCmdErr tagName
)
<|>
(try $ do (tagName, tagAttrs) <- emptyTag
, bCmdAttributes = tagAttrs
, bCmdContents = []
}
- _ -> pzero
+
+ Just InlineCommandType
+ -> pzero
+
+ _ -> return $ undefinedCmdErr tagName
)
<?>
"block command"
<|>
return []
+ undefinedCmdErr :: String -> BlockElement
+ undefinedCmdErr name
+ = Div [("class", "error")]
+ [ Paragraph [Text ("The command `" ++ name ++ "' is not defined. " ++
+ "Make sure you haven't mistyped.")
+ ]
+ ]
+
inlineElement :: CommandTypeOf -> Parser InlineElement
inlineElement cmdTypeOf
foldr (<|>) pzero [ cdata
, apostrophes cmdTypeOf
, text
+ , objLink
, pageLink
+ , extLink
, inlineCmd cmdTypeOf
]
apos n = count n (char '\'') >> notFollowedBy (char '\'')
+objLink :: Parser InlineElement
+objLink = do try (string "[[[")
+ page <- many1 (noneOf "|]")
+ text <- option Nothing
+ (char '|' >> many1 (satisfy (/= ']')) >>= return . Just)
+ string "]]]"
+ return $ ObjectLink page text
+ <?>
+ "object link"
+
+
pageLink :: Parser InlineElement
pageLink = do try (string "[[")
page <- option Nothing
"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