JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
change parse_html() calling conventions
authorJason Woofenden <jason@jasonwoof.com>
Thu, 21 Jan 2016 18:18:17 +0000 (13:18 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 21 Jan 2016 18:18:17 +0000 (13:18 -0500)
parse-html.coffee
test.coffee

index 9f3292b..a6d501f 100644 (file)
 #
 # Call it like this:
 #
-#     wheic.parse_html({html: "<p><b>hi</p>"})
+#     wheic.parse_html("<p><b>hi</p>")
 #
 # Or, if you don't want <html><head><body>/etc, do this:
 #
-#     wheic.parse_html({fragment: "body", html: "<p><b>hi</p>"})
+#     wheic.parse_html("<p><b>hi</p>", {fragment: "body"})
 #
 # return value is an array of Nodes, see "class Node" below.
 
@@ -627,7 +627,7 @@ decode_named_char_ref = (txt) ->
        decoded = _decode_named_char_ref txt
        return decode_named_char_ref_cache[txt] = decoded
 
-parse_html = (args) ->
+parse_html = (args_html, args = {}) ->
        txt = null
        cur = null # index of next char in txt to be parsed
        # declare doc and tokenizer variables so they're in scope below
@@ -4612,7 +4612,7 @@ parse_html = (args) ->
 
        # tree constructor initialization
        # see comments on TYPE_TAG/etc for the structure of this data
-       txt = args.html
+       txt = args_html
        cur = 0
        doc = new Node TYPE_TAG, name: 'document', namespace: NS_HTML
        doc.flag 'quirks mode', QUIRKS_NO # TODO bugreport spec for not specifying this
index 62b297c..fabb61b 100644 (file)
@@ -7979,7 +7979,7 @@ test_parser = (args) ->
        args.error_cb = (i) ->
                parse_errors.push i
        prev_node_id = 0 # reset counter
-       parsed = wheic.parse_html args
+       parsed = wheic.parse_html args.html, args
        serialized = serialize_els parsed
        if serialized isnt args.expected
                test_results.failed += 1