Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EBNF notation for HTML5 tag syntax
tag-open := '<' tag-name ws* attr-list? ws* '>'
tag-empty := '<' tag-name ws* attr-list? ws* '/>'
tag-close := '</' tag-name ws* '>'
attr-list := (ws+ attr)*
attr := attr-empty | attr-unquoted | attr-single-quoted | attr-double-quoted
attr-empty := attr-name
attr-unquoted := attr-name ws* = ws* attr-unquoted-value
attr-single-quoted := attr-name ws* = ws* ' attr-single-quoted-value '
attr-double-quoted := attr-name ws* = ws* " attr-double-quoted-value "
tag-name := (alphabets | digits)+ # Can digits become first letter?
attr-name := /[^\s"'>/=\p{Control}]+/
# These three items should not contain 'ambiguous ampersand'...
attr-unquoted-value := /[^\s"'=<>`]+/
attr-single-quoted-value := /[^']*/
attr-double-quoted-value := /[^"]*/
alphabets := [a-zA-Z]
digits := /[0-9]/
ws := /\s/
@tkqubo

This comment has been minimized.

@MrOutput

This comment has been minimized.

Copy link

@MrOutput MrOutput commented Oct 9, 2017

very cool, thanks for making this

@SpineyPete

This comment has been minimized.

Copy link

@SpineyPete SpineyPete commented Jul 7, 2018

Just what I needed! Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment