diff options
Diffstat (limited to 'stdlib/source/library/lux/data/format/markdown.lux')
-rw-r--r-- | stdlib/source/library/lux/data/format/markdown.lux | 324 |
1 files changed, 162 insertions, 162 deletions
diff --git a/stdlib/source/library/lux/data/format/markdown.lux b/stdlib/source/library/lux/data/format/markdown.lux index b04f60806..8f64a70f0 100644 --- a/stdlib/source/library/lux/data/format/markdown.lux +++ b/stdlib/source/library/lux/data/format/markdown.lux @@ -31,170 +31,170 @@ (text.replaced "." "\.") (text.replaced "!" "\!"))) -(abstract: .public Span Any []) -(abstract: .public Block Any []) +(abstract: .public Span Any) +(abstract: .public Block Any) (abstract: .public (Markdown brand) Text - [(def: .public empty - Markdown - (:abstraction "")) - - (def: .public text - (-> Text (Markdown Span)) - (|>> ..safe :abstraction)) - - (def: blank_line - (format text.new_line text.new_line)) - - (template [<name> <prefix>] - [(def: .public (<name> content) - (-> Text (Markdown Block)) - (:abstraction (format <prefix> " " (..safe content) ..blank_line)))] - - [heading/1 "#"] - [heading/2 "##"] - [heading/3 "###"] - [heading/4 "####"] - [heading/5 "#####"] - [heading/6 "######"] - ) - - (def: (block content) - (-> Text (Markdown Block)) - (:abstraction (format content ..blank_line))) - - (def: .public paragraph - (-> (Markdown Span) (Markdown Block)) - (|>> :representation ..block)) - - (def: .public break - (Markdown Span) - (:abstraction (format " " text.new_line))) - - (template [<name> <wrapper>] - [(def: .public <name> - (-> (Markdown Span) (Markdown Span)) - (|>> :representation - (text.enclosed [<wrapper> <wrapper>]) - :abstraction))] - - [bold "**"] - [italic "_"] - ) - - (def: (prefix with) - (-> Text (-> Text Text)) - (|>> (text.all_split_by text.new_line) - (list\each (function (_ line) - (if (text.empty? line) - line - (format with line)))) - (text.interposed text.new_line))) - - (def: indent - (-> Text Text) - (..prefix text.tab)) - - (def: .public quote - (-> (Markdown Block) (Markdown Block)) - (|>> :representation - (..prefix "> ") - :abstraction)) - - (def: .public numbered_list - (-> (List [(Markdown Span) (Maybe (Markdown Block))]) - (Markdown Block)) - (|>> list.enumeration - (list\each (function (_ [idx [summary detail]]) - (format "1. " (:representation summary) - (case detail - {#.Some detail} - (|> detail - :representation - ..indent - (text.enclosed [text.new_line text.new_line]) - (format text.new_line)) - - #.None - "")))) - (text.interposed text.new_line) - ..block)) - - (def: .public bullet_list - (-> (List [(Markdown Span) (Maybe (Markdown Block))]) - (Markdown Block)) - (|>> (list\each (function (_ [summary detail]) - (format "* " (:representation summary) - (case detail - {#.Some detail} - (|> detail - :representation - ..indent - (text.enclosed [text.new_line text.new_line]) - (format text.new_line)) - - #.None - "")))) - (text.interposed text.new_line) - ..block)) - - ... A snippet of code. - (def: .public snippet - (-> Text (Markdown Span)) - (|>> (text.enclosed ["`` " " ``"]) :abstraction)) - - ... A (generic) block of code. - (def: .public generic_code - (-> Text (Markdown Block)) - (let [open (format "```" text.new_line) - close (format text.new_line "```")] - (|>> (text.enclosed [open close]) ..block))) - - ... A block of code of a specific language. - (def: .public (code language block) - (-> Text Text (Markdown Block)) - (let [open (format "```" language text.new_line) - close (format text.new_line "```")] - (|> block - (text.enclosed [open close]) - ..block))) - - (def: .public (image description url) - (-> Text URL (Markdown Span)) - (:abstraction (format "![" (..safe description) "](" url ")"))) - - (def: .public horizontal_rule - (Markdown Block) - (..block "___")) - - (def: .public (link description url) - (-> (Markdown Span) URL (Markdown Span)) - (:abstraction (format "[" (:representation description) "](" url ")"))) - - (type: .public Email - Text) - - (template [<name> <type>] - [(def: .public <name> - (-> <type> (Markdown Span)) - (|>> (text.enclosed ["<" ">"]) :abstraction))] - - [url URL] - [email Email] - ) - - (template [<name> <brand> <infix>] - [(def: .public (<name> pre post) - (-> (Markdown <brand>) (Markdown <brand>) (Markdown <brand>)) - (:abstraction (format (:representation pre) <infix> (:representation post))))] - - [and Span " "] - [then Block ""] - ) - - (def: .public markdown - (All (_ a) (-> (Markdown a) Text)) - (|>> :representation))] + (def: .public empty + Markdown + (:abstraction "")) + + (def: .public text + (-> Text (Markdown Span)) + (|>> ..safe :abstraction)) + + (def: blank_line + (format text.new_line text.new_line)) + + (template [<name> <prefix>] + [(def: .public (<name> content) + (-> Text (Markdown Block)) + (:abstraction (format <prefix> " " (..safe content) ..blank_line)))] + + [heading/1 "#"] + [heading/2 "##"] + [heading/3 "###"] + [heading/4 "####"] + [heading/5 "#####"] + [heading/6 "######"] + ) + + (def: (block content) + (-> Text (Markdown Block)) + (:abstraction (format content ..blank_line))) + + (def: .public paragraph + (-> (Markdown Span) (Markdown Block)) + (|>> :representation ..block)) + + (def: .public break + (Markdown Span) + (:abstraction (format " " text.new_line))) + + (template [<name> <wrapper>] + [(def: .public <name> + (-> (Markdown Span) (Markdown Span)) + (|>> :representation + (text.enclosed [<wrapper> <wrapper>]) + :abstraction))] + + [bold "**"] + [italic "_"] + ) + + (def: (prefix with) + (-> Text (-> Text Text)) + (|>> (text.all_split_by text.new_line) + (list\each (function (_ line) + (if (text.empty? line) + line + (format with line)))) + (text.interposed text.new_line))) + + (def: indent + (-> Text Text) + (..prefix text.tab)) + + (def: .public quote + (-> (Markdown Block) (Markdown Block)) + (|>> :representation + (..prefix "> ") + :abstraction)) + + (def: .public numbered_list + (-> (List [(Markdown Span) (Maybe (Markdown Block))]) + (Markdown Block)) + (|>> list.enumeration + (list\each (function (_ [idx [summary detail]]) + (format "1. " (:representation summary) + (case detail + {#.Some detail} + (|> detail + :representation + ..indent + (text.enclosed [text.new_line text.new_line]) + (format text.new_line)) + + #.None + "")))) + (text.interposed text.new_line) + ..block)) + + (def: .public bullet_list + (-> (List [(Markdown Span) (Maybe (Markdown Block))]) + (Markdown Block)) + (|>> (list\each (function (_ [summary detail]) + (format "* " (:representation summary) + (case detail + {#.Some detail} + (|> detail + :representation + ..indent + (text.enclosed [text.new_line text.new_line]) + (format text.new_line)) + + #.None + "")))) + (text.interposed text.new_line) + ..block)) + + ... A snippet of code. + (def: .public snippet + (-> Text (Markdown Span)) + (|>> (text.enclosed ["`` " " ``"]) :abstraction)) + + ... A (generic) block of code. + (def: .public generic_code + (-> Text (Markdown Block)) + (let [open (format "```" text.new_line) + close (format text.new_line "```")] + (|>> (text.enclosed [open close]) ..block))) + + ... A block of code of a specific language. + (def: .public (code language block) + (-> Text Text (Markdown Block)) + (let [open (format "```" language text.new_line) + close (format text.new_line "```")] + (|> block + (text.enclosed [open close]) + ..block))) + + (def: .public (image description url) + (-> Text URL (Markdown Span)) + (:abstraction (format "![" (..safe description) "](" url ")"))) + + (def: .public horizontal_rule + (Markdown Block) + (..block "___")) + + (def: .public (link description url) + (-> (Markdown Span) URL (Markdown Span)) + (:abstraction (format "[" (:representation description) "](" url ")"))) + + (type: .public Email + Text) + + (template [<name> <type>] + [(def: .public <name> + (-> <type> (Markdown Span)) + (|>> (text.enclosed ["<" ">"]) :abstraction))] + + [url URL] + [email Email] + ) + + (template [<name> <brand> <infix>] + [(def: .public (<name> pre post) + (-> (Markdown <brand>) (Markdown <brand>) (Markdown <brand>)) + (:abstraction (format (:representation pre) <infix> (:representation post))))] + + [and Span " "] + [then Block ""] + ) + + (def: .public markdown + (All (_ a) (-> (Markdown a) Text)) + (|>> :representation)) ) |