A Pure Elm Markdown Parser

Image for post
Image for post
Elm.Markdown.toHtml : Option -> String -> Html msg
Elm.Markdown.toHtml ExtendedMath "Pythagoras said $a^2 + b^2 = c^2$"

The Parser

type Block = Block BlockType Level Content
Introduction
Biology
Plants
Flowering
Non-flowering
Animals
Furry
Non-furry
Chemistry
Organic
Inorganic

Digging a little deeper

type FSM = State (List Block) Register
type State
= Start
| InBlock Block
| Error
runFSM : Option -> String -> FSM
runFSM option str =
let
folder : String -> FSM -> FSM
folder =
\line fsm -> nextState option line fsm
in
List.foldl folder initialFSM (splitIntoLines str)
nextState : Option -> String -> FSM -> FSM

From Annotated Lists to Rose Trees

fromList : a -> (a -> Int) -> List a -> Tree a

Compliance with CommonMark, Plans

Written by

jxxcarlson on elm slack, http://jxxcarlson.github.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store