mediawiki-extensions-Visual.../tests/parser/__patched-html5-parser.coffee
au 0ca9b00100 * Convert __patched-html-parser to .coffee.
Note that the compiled .js file (generated by "make"/"make test")
  is still under version control so folks can work on the project
  even without a running "coffee" command in PATH.

  Also updated README to mention coffee-script and "make test".
2012-02-18 18:54:12 +00:00

31 lines
1 KiB
CoffeeScript

module.exports = (HTML5) ->
htmlparser = new HTML5.Parser
htmlparser.tree.elementInActiveFormattingElements = (name) ->
els = @activeFormattingElements
i = els.length - 1
while i >= 0
break if els[i].type is HTML5.Marker.type
return els[i] if els[i].tagName.toLowerCase() is name
i--
return false
htmlparser.tree.reconstructActiveFormattingElements = ->
return if @activeFormattingElements.length is 0
i = @activeFormattingElements.length - 1
entry = @activeFormattingElements[i]
return if entry.type is HTML5.Marker.type or @open_elements.indexOf(entry) isnt -1
while entry.type isnt HTML5.Marker.type and @open_elements.indexOf(entry) is -1
i -= 1
entry = @activeFormattingElements[i]
break unless entry
loop
i += 1
clone = @activeFormattingElements[i].cloneNode()
element = @insert_element(clone.tagName, clone.attributes)
@activeFormattingElements[i] = element
break if element is @activeFormattingElements.last()
return
return htmlparser