markdown = { (elements | element_inner | text | new_line)* } elements = { h1 | h2 | italic_text | bold_text | code_text } h1 = { "# " ~ (elements | element_inner | text ) + ~ "\n" } h2 = { "## " ~ (elements | element_inner | text ) + ~ "\n" } italic_text = { ("_" ~ element_inner ~ "_") | ("*" ~ element_inner ~ "*") } bold_text = { ("__" ~ element_inner ~ "__") | ("**" ~ element_inner ~ "**") } code_text = { "`" ~ element_inner ~ "`" } element_inner = { (!("_") ~ ! ("*") ~ !("`") ~ !("\n") ~ ANY)+ } text = { (!("\n") ~ ANY)+ } new_line = { NEWLINE }