@id = "#{args.id}+"
else
@id = "#{++prev_node_id}"
- shallow_clone: -> # return a new node that's the same except without the children or parent
- # WARNING this doesn't work right on open tags that are still being parsed
- attrs = {}
- attrs[k] = v for k, v of @attrs
- return new Node @type, name: @name, text: @text, attrs: attrs, namespace: @namespace, id: @id, token: @token
acknowledge_self_closing: ->
if @token?
@token.flag 'did_self_close'
ret += 'comment:'
ret += JSON.stringify @text
when TYPE_DOCTYPE
- ret += 'doctype'
- # FIXME
+ ret += "doctype:#{@name},#{JSON.stringify(@public_identifier ? '')},#{JSON.stringify(@system_identifier ? '')}"
when TYPE_AFE_MARKER
ret += 'marker'
when TYPE_AAA_BOOKMARK
if scope2[t.name] is t.namespace
return false
return false
- standard_scopers = { # FIXME these are supposed to be namespace specific
+ standard_scopers = {
applet: NS_HTML, caption: NS_HTML, html: NS_HTML, table: NS_HTML,
td: NS_HTML, th: NS_HTML, marquee: NS_HTML, object: NS_HTML,
template: NS_HTML, mi: NS_MATHML,
if node.name is 'html'
# 1. If the head element pointer is null, switch the insertion
# mode to "before head" and abort these steps. (fragment case)
- # fixfull (fragment case)
-
- # 2. Otherwise, the head element pointer is not null, switch
- # the insertion mode to "after head" and abort these steps.
- insertion_mode = ins_mode_in_body # FIXME fixfull
+ if head_element_pointer is null
+ ins_mode = ins_mode_before_head
+ else
+ # 2. Otherwise, the head element pointer is not null,
+ # switch the insertion mode to "after head" and abort these
+ # steps.
+ insertion_mode = ins_mode_after_head
return
# 17. If last is true, then switch the insertion mode to "in body"
# and abort these steps. (fragment case)
break
# Create
loop
- el = afe[i].shallow_clone()
- tree_insert_element el
+ el = insert_html_element afe[i].token
afe[i] = el
break if i is 0
i -= 1 # Advance
# element, replace the entry for node in the stack of open
# elements with an entry for the new element, and let node be
# the new element.
- new_node = node.shallow_clone()
+ new_node = token_to_element node.token, NS_HTML, ca
for t, i in afe
if t is node
afe[i] = new_node
# 15. Create an element for the token for which formatting element
# was created, in the HTML namespace, with furthest block as the
# intended parent.
- new_element = fe.shallow_clone() # FIXME intended parent thing
+ new_element = token_to_element fe.token, NS_HTML, fb
# 16. Take all of the child nodes of furthest block and append them
# to the element created in the last step.
while fb.children.length
# http://www.w3.org/TR/html5/syntax.html#create-an-element-for-the-token
# aka create_an_element_for_token
token_to_element = (t, namespace, intended_parent) ->
- t.type = TYPE_TAG # not TYPE_START_TAG
# convert attributes into a hash
attrs = {}
- while t.attrs_a.length
- a = t.attrs_a.pop()
+ for a in t.attrs_a
attrs[a[0]] = a[1] # TODO check what to do with dupilcate attrs
el = new Node TYPE_TAG, name: t.name, namespace: namespace, attrs: attrs, token: t
# http://www.w3.org/TR/html5/syntax.html#insert-an-html-element
insert_html_element = insert_foreign_element # (token, namespace) ->
- # FIXME read implement "foster parenting" part
- # FIXME read spec, do this right
- # FIXME implement the override target thing
- # note: this assumes it's an open tag
- # FIXME what part of the spec is this?
- # TODO look through all callers of this, and see what they should really be doing.
- # eg probably insert_html_element for tokens
- tree_insert_element = (el, override_target = null, namespace = null) ->
- if namespace?
- el.namespace = namespace
- dest = adjusted_insertion_location override_target
- if el.type is TYPE_START_TAG # means it's a "token"
- el = token_to_element el, namespace, dest[0]
- unless el.namespace?
- namespace = dest.namespace
- # fixfull: Document nodes sometimes can't accept more chidren
- dest[0].children.splice dest[1], 0, el
- el.parent = dest[0]
- open_els.unshift el
- return el
-
# http://www.w3.org/TR/html5/syntax.html#insert-a-comment
# position should be [node, index_within_children]
insert_comment = (t, position = null) ->