Skip to content

Instantly share code, notes, and snippets.

@wreulicke
Forked from takahashim/micromark_syn.txt
Last active August 28, 2016 18:11
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 wreulicke/411c16b15214d824c06e21a8f21d2bdf to your computer and use it in GitHub Desktop.
Save wreulicke/411c16b15214d824c06e21a8f21d2bdf to your computer and use it in GitHub Desktop.
markdown用peg
start = doc
doc = block:block+ {
return block;
}
block = list / line / code / heading / blankline / sentence
list = l:(whitespace "* " chars blankline?)+ {
return {
type:"list",
list: l.map(function(list){return list[2];})
};
}
line = "---" "-"* blankline? {return {type:"line"}}
//link = ! {false}
//image = ! {false}
//quotation = ! {false}
heading = prefix:"#"+ " " text:text {
return {
type:"heading",
text:text
}
}
sentence = text:text {
return {type:"sentence",text:text}
}
code = "```" lang:chars? text:code_content "```" blankline? {
return {
type:"code",
lang:lang||"",
text:text.trim()
};
}
text = t:chars blankline? {
return t;
}
code_content=
$(nobackchars "`" code_content)
/ $(nobackchars "``" code_content)
/ $nobackchars
blankline = [\n] { return {type:"blank"}; }
chars = $[^\n]+
nobackchars = $[^`]+
whitespace=[ \t\n\r]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment