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 ""
27 , (parseWiki "=heading="
29 (Right [ Heading 1 "heading" ]))
31 , (parseWiki "== heading == \n"
33 (Right [ Heading 2 "heading" ]))
35 , (parseWiki "===== hello world =====\n"
37 (Right [ Heading 5 "hello world" ]))
39 , (parseWiki "a =not a heading="
41 (Right [ Paragraph [ Text "a =not a heading=" ]
44 , (parseWiki "=h=\n\n=h="
46 (Right [ Heading 1 "h"
49 , (parseWiki "foo\nbar"
51 (Right [ Paragraph [ Text "foo"
56 , (parseWiki "foo\nbar\n\nbaz\n"
58 (Right [ Paragraph [ Text "foo"
62 , Paragraph [ Text "baz"
66 , (parseWiki "foo\n\n\nbar"
68 (Right [ Paragraph [ Text "foo" ]
69 , Paragraph [ Text "bar" ]
72 , (parseWiki "foo\n=h="
74 (Right [ Paragraph [ Text "foo" ]
78 , (parseWiki "<!-- comment -->"
82 , (parseWiki "<!-- comment -->foo"
84 (Right [ Paragraph [ Text "foo" ]
87 , (parseWiki "bar<!-- comment -->"
89 (Right [ Paragraph [ Text "bar" ]
92 , (parseWiki "foo<!-- comment -->bar"
94 (Right [ Paragraph [ Text "foo"
99 , (parseWiki "<!-- comment -->=h="
101 (Right [ Heading 1 "h" ]))
103 , (parseWiki "=h= <!---->"
105 (Right [ Heading 1 "h" ]))
107 , (parseWiki "<!-- <!-- nested --> comment -->"
111 , (parseWiki "[[Page]]"
113 (Right [ Paragraph [ PageLink (Just "Page") Nothing Nothing ]
116 , (parseWiki "[[Page|Link to \"Page\"]]"
118 (Right [ Paragraph [ PageLink (Just "Page") Nothing (Just "Link to \"Page\"") ]
121 , (parseWiki "[[Page#foo]]"
123 (Right [ Paragraph [ PageLink (Just "Page") (Just "foo") Nothing ]
126 , (parseWiki "[[#foo]]"
128 (Right [ Paragraph [ PageLink Nothing (Just "foo") Nothing ]
131 , (parseWiki "[[Page#foo|Link to \"Page#foo\"]]"
133 (Right [ Paragraph [ PageLink (Just "Page") (Just "foo") (Just "Link to \"Page#foo\"") ]
136 , (parseWiki "foo [[Bar]] baz"
138 (Right [ Paragraph [ Text "foo "
139 , PageLink (Just "Bar") Nothing Nothing
144 , (parseWiki "[[Foo]]\n[[Bar]]"
146 (Right [ Paragraph [ PageLink (Just "Foo") Nothing Nothing
148 , PageLink (Just "Bar") Nothing Nothing