Skip to content

Instantly share code, notes, and snippets.

@akkijp
Created July 14, 2017 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akkijp/7d4fd11e66878e516f78222fa15a5c1b to your computer and use it in GitHub Desktop.
Save akkijp/7d4fd11e66878e516f78222fa15a5c1b to your computer and use it in GitHub Desktop.
💩 markdownパーサ
start = doc
doc = block:block + {
return `<body>${block.join("")}</body>`;
}
block = headline
/ paragraph
headline = prefix:("#" / "##" / "###" / "####" / "#####" / "######") textline:TEXT_LINE EOS {
return `<h${prefix.length}>${textline}</h${prefix.length}>`
}
paragraph = textline:TEXT_LINE+ {
return `<p>${textline.join("<br />")}</p>`
}
TEXT_LINE = ch:[^\n]+ EOS { return ch.join(""); }
BLANK_LINE = [\n]
EOS
= EOL
/ EOF
EOL
= "\n"
EOF
= !.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment