# Live Scripting HTML Parser

## Markup to test (permalink, Live DOM Viewer)

<html> <head></head><body> <p> <script> document.write ('aaaaaaa</p><script>document.write("cccccc");</', 'script>bbbbbb'); </script> <p>

## Log

## Notes

This is a simplified implementation of HTML5 Parsing Algorithm (revision 2138). It only implements scripting-related parts of the algorithm. Especially, this parser:

- Does not support `DOCTYPE` and comment tokens.
- Does not support entities except for `&quot;`, `&apos;`, and `&amp;` in `script` `src` attribute value.
- Does not support omissions of start or end tags, the AAA algorithm, and so on.
- Does not raise parse errors for invalid attribute specifications in start or end tags.
- Does not support RCDATA elements (`title` and `textarea`).
- Does not strip the first newline in `pre`, `listing`, and `textarea` elements.
- Does not support `<!--`..`-->` parsing rule in CDATA/RCDATA elements.
- Does not support foreign (SVG or MathML) elements.
- Only supports `script` `type` `text/javascript`. `type` and `language` attributes are ignored.
- Only supports limited statements. It must consist of zero or more of statements looking similar to the following statements, possibly introduced, followed, or separated by white space characters:
  - `document.write ("string", ["string", ...]);`.
  - `var s = document.createElement ("script"); s.src = "string"; document.documentElement.appendChild (s);`
  - `w (document.documentElement.innerHTML);` (This statement can be used to dump the document, even when the document has no document element. The output format is the tree dump format used in html5lib test data, not HTML.)
  Note that strings may be delimited by `'`s instead of `"`s.
- Only supports `javascript:` URI scheme in the `src` attribute of the `script` element. In addition, the URI must be conform to the regular expression `^javascript:\s*(?:"[^"]*"|'[^']*')\s*$`.
- Only supports `\uHHHH` escapes in JavaScript string literals.
- Does not handle stop parsing phase correctly if the document is replaced by `document.open ()` call. In other word, delayed (deferred or asynchronous) script executions and event firings might be treated in a wrong way if a `document.open ()` invocation is implicitly done by `document.write ()` in a delayed script.

For some reason, this parser does not work in browsers that do not support JavaScript 1.5.

See also SuikaWiki: Live Scripting HTML Parser.