0 | ||| This is the main module of the Markdown library.
 1 | |||
 2 | ||| It is probably the only one you will need to import with its main three
 3 | ||| functions `toHtml`, `parse` and `parse_either` further described below.
 4 | module Text.Markdown
 5 |
 6 | import Text.Lexer
 7 |
 8 | import Text.Markdown.Errors
 9 | import Text.Markdown.Lexer
10 | import Text.Markdown.Parser
11 |
12 | import public Text.Markdown.Data
13 | import public Text.Markdown.Format.Html
14 |
15 | %default total
16 |
17 | ||| Parses a Markdown string with a possibility of failure.
18 | |||
19 | ||| This function is intended for debugging as "normally" the parser shouldn't
20 | ||| fail. If this happens, run this function and kindly report the issue with
21 | ||| a minimal example.
22 | export
23 | parse_either : String -> Either MdError Markdown
24 | parse_either x = lexMarkdown x >>= parseMarkdown
25 |
26 | ||| Parses a Markdown string.
27 | |||
28 | ||| In case of failure of the parser (which shouldn't happen!) returns an empty
29 | ||| markdown.
30 | |||
31 | ||| If a failure would happen, this is a bug. Kindly report it with a minimal
32 | ||| example using `parse_either`.
33 | export
34 | parse : String -> Markdown
35 | parse x =
36 |   case parse_either x of
37 |     Right markdown => markdown
38 |     Left _         => Doc []
39 |
40 | ||| Converts a markdown string to a HTML string.
41 | export
42 | covering
43 | toHtml : String -> String
44 | toHtml = toHtml . parse
45 |