7 import Rakka.Wiki.Parser
9 import Text.ParserCombinators.Parsec
12 parseWiki :: String -> Either String WikiPage
13 parseWiki src = case parse wikiPage "" src of
14 Left err -> Left (show err)
15 Right page -> Right page
19 testData = [ (parseWiki ""
23 , (parseWiki "=heading="
25 (Right [Block (Heading 1 "heading")]))
27 , (parseWiki "== heading == \n"
29 (Right [Block (Heading 2 "heading")]))
31 , (parseWiki "===== hello world =====\n"
33 (Right [Block (Heading 5 "hello world")]))
35 , (parseWiki "a =not a heading="
37 (Right [Inline (Text "a =not a heading=")]))
39 , (parseWiki "=h=\n\n=h="
41 (Right [ Block (Heading 1 "h")
42 , Block (Heading 1 "h")
45 , (parseWiki "foo\nbar\n\nbaz\n"
47 (Right [ Inline (Text "foo")
55 , (parseWiki "foo\n\n\nbar"
57 (Right [ Inline (Text "foo")
62 , (parseWiki "foo\n=h="
64 (Right [ Inline (Text "foo")
66 , Block (Heading 1 "h")
69 , (parseWiki "<!-- comment -->"
73 , (parseWiki "<!-- comment -->foo"
75 (Right [Inline (Text "foo")]))
77 , (parseWiki "foo<!-- comment -->"
79 (Right [Inline (Text "foo")]))
81 , (parseWiki "foo<!-- comment -->bar"
83 (Right [ Inline (Text "foo")
87 , (parseWiki "<!-- comment -->=h="
89 (Right [Block (Heading 1 "h")]))
91 , (parseWiki "=h= <!---->"
93 (Right [Block (Heading 1 "h")]))
95 , (parseWiki "<!-- <!-- nested --> comment -->"
99 , (parseWiki "[[Page]]"
101 (Right [Inline (PageLink (Just "Page") Nothing Nothing)]))
103 , (parseWiki "[[Page|Link to \"Page\"]]"
105 (Right [Inline (PageLink (Just "Page") Nothing (Just "Link to \"Page\""))]))
107 , (parseWiki "[[Page#foo]]"
109 (Right [Inline (PageLink (Just "Page") (Just "foo") Nothing)]))
111 , (parseWiki "[[#foo]]"
113 (Right [Inline (PageLink Nothing (Just "foo") Nothing)]))
115 , (parseWiki "[[Page#foo|Link to \"Page#foo\"]]"
117 (Right [Inline (PageLink (Just "Page") (Just "foo") (Just "Link to \"Page#foo\""))]))
119 , (parseWiki "foo [[Bar]] baz"
121 (Right [ Inline (Text "foo ")
122 , Inline (PageLink (Just "Bar") Nothing Nothing)
123 , Inline (Text " baz")
126 , (parseWiki "[[Foo]]\n[[Bar]]"
128 (Right [ Inline (PageLink (Just "Foo") Nothing Nothing)
130 , Inline (PageLink (Just "Bar") Nothing Nothing)