X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=blobdiff_plain;f=parser.coffee;h=a1d41cd6b2c17f7d7c01f04c69373ff3bcf5415d;hp=509e4927f7dbd2e981a766b65fbbc86efefdda94;hb=e3b396215f59cd45b7d7c510dcddea8354f756aa;hpb=c052fef9484e52df1ac860610ce1620c9a3420c2 diff --git a/parser.coffee b/parser.coffee index 509e492..a1d41cd 100644 --- a/parser.coffee +++ b/parser.coffee @@ -43,11 +43,11 @@ # # Call it like this: # -# wheic_parser.parse("

hi

") +# peach_parser.parse("

hi

") # # Or, if you don't want /etc, do this: # -# wheic_parser.parse("

hi

", {fragment: "body"}) +# peach_parser.parse("

hi

", {fragment: "body"}) # # return value is an array of Nodes, see "class Node" below. @@ -80,8 +80,8 @@ if (typeof module) isnt 'undefined' and module.exports? exports = module.exports else context = 'browser' - window.wheic_parser = {} - exports = window.wheic_parser + window.peach_parser = {} + exports = window.peach_parser from_code_point = (x) -> if String.fromCodePoint? @@ -93,10 +93,10 @@ from_code_point = (x) -> return String.fromCharCode((x >> 10) + 0xd800, (x % 0x400) + 0xdc00) # Each node is an obect of the Node class. Here are the Node types: -TYPE_TAG = 0 # name, {attributes}, [children] -TYPE_TEXT = 1 # "text" -TYPE_COMMENT = 2 -TYPE_DOCTYPE = 3 +TYPE_TAG = 'tag' # name, {attributes}, [children] +TYPE_TEXT = 'text' # "text" +TYPE_COMMENT = 'comment' +TYPE_DOCTYPE = 'doctype' # the following types are emited by the tokenizer, but shouldn't end up in the tree: TYPE_START_TAG = 4 # name, [attributes ([key,value]...) in reverse order], [children] TYPE_END_TAG = 5 # name @@ -105,14 +105,14 @@ TYPE_AFE_MARKER = 7 # http://www.w3.org/TR/html5/syntax.html#reconstruct-the-act TYPE_AAA_BOOKMARK = 8 # http://www.w3.org/TR/html5/syntax.html#adoption-agency-algorithm # namespace constants -NS_HTML = 1 -NS_MATHML = 2 -NS_SVG = 3 +NS_HTML = 'html' +NS_MATHML = 'mathml' +NS_SVG = 'svg' # quirks mode constants -QUIRKS_NO = 1 -QUIRKS_LIMITED = 2 -QUIRKS_YES = 3 +QUIRKS_NO = 'no' +QUIRKS_LIMITED = 'limited' +QUIRKS_YES = 'yes' # queue up debug logs, so eg they can be shown only for tests that fail g_debug_log = [] @@ -1246,6 +1246,7 @@ parse_html = (args_html, args = {}) -> prev.text += t.text return dest[0].children.splice dest[1], 0, t + t.parent = dest[0] return # 8.2.5 http://www.w3.org/TR/html5/syntax.html#tree-construction @@ -4732,6 +4733,7 @@ parse_html = (args_html, args = {}) -> return doc.children exports.parse = parse_html +exports.Node = Node exports.debug_log_reset = debug_log_reset exports.debug_log_each = debug_log_each exports.TYPE_TAG = TYPE_TAG