Created
July 14, 2017 14:35
-
-
Save 4mitch/dd16b4172741669ad963933e1af027fb to your computer and use it in GitHub Desktop.
PEG.JS html parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start = root | |
root = xml:xml { return {xml} } | |
xml = tag | |
tag = tagopen:tagopen innerHTML:(tag / text)* tagclose | |
{ let a = {}; a[tagopen.valueOf()]= innerHTML; return a } | |
tagopen = _ "<" text:text ">" _ { return text } | |
tagclose = _ "</" text:text ">" _ { return text } | |
text = all+ { return text() } | |
all = _ text:n _ { return text } | |
n "notWhitespace" = | |
[^<>/]+ {return ""} | |
_ "whitespace" = | |
[ \t\n\r]* {return ""} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment