import Text.ParserCombinators.Parsec
+cmdTypeOf :: String -> Maybe CommandType
+cmdTypeOf "br" = Just InlineCommandType
+cmdTypeOf "i" = Just InlineCommandType
+cmdTypeOf "b" = Just InlineCommandType
+cmdTypeOf "span" = Just InlineCommandType
+cmdTypeOf "div" = Just BlockCommandType
+cmdTypeOf _ = Nothing
+
+
parseWiki :: String -> Either String WikiPage
-parseWiki src = case parse wikiPage "" src of
+parseWiki src = case parse (wikiPage cmdTypeOf) "" src of
Left err -> Left (show err)
Right page -> Right page
, List (ListElement Numbered [ [Right (Text "b")] ])
]))
+ , (parseWiki "*a<!-- comment -->"
+ ~?=
+ (Right [ List (ListElement Bullet [ [Right (Text "a")] ]) ]))
+
+ , (parseWiki "*a<!-- comment -->\n*b"
+ ~?=
+ (Right [ List (ListElement Bullet [ [Right (Text "a")]
+ , [Right (Text "b")]
+ ])
+ ]))
+
, (parseWiki "foo:bar"
~?=
(Right [ Paragraph [ Text "foo"
, (parseWiki "'''''foo'''''"
~?=
(Right [ Paragraph [ Italic [Bold [Text "foo"]] ] ]))
+
+ , (parseWiki "<br />"
+ ~?=
+ (Right [ Paragraph [ InlineCmd (InlineCommand "br" [] []) ] ]))
+
+ , (parseWiki "<br style=\"clear: both\"/>"
+ ~?=
+ (Right [ Paragraph [ InlineCmd (InlineCommand "br" [("style", "clear: both")] []) ] ]))
+
+ , (parseWiki "<i><b>foo</b></i>"
+ ~?=
+ (Right [ Paragraph [ InlineCmd (InlineCommand "i" []
+ [ InlineCmd (InlineCommand "b" [] [ Text "foo" ]) ]) ] ]))
+
+ , (parseWiki "<i>\nfoo\n<!-- comment -->\nbar</i>"
+ ~?=
+ (Right [ Paragraph [ InlineCmd (InlineCommand "i" []
+ [ Text "\n"
+ , Text "foo"
+ , Text "\n"
+ , Text "\n"
+ , Text "bar"
+ ]) ] ]))
]