'use babel'

import AnsiUp from 'ansi_up'
let converter = new AnsiUp()
converter.escape_for_html = false

export default function ansiToHTML (view) {
  if (view.childElementCount == 0) {
    view.innerHTML = converter.ansi_to_html(view.innerHTML)
  } else if (view.querySelectorAll) {
    let allNodes = view.querySelectorAll  ('*')
    for (let i = -1, l = allNodes.length; ++i < l;) {
      if (allNodes[i].childElementCount == 0) {
        allNodes[i].innerHTML = converter.ansi_to_html(allNodes[i].innerHTML)
      }
    }
  }
  return view
}

@@ -99,16 +99,537 @@
  false%0A%0A
+// this wraps all plain text nodes in a span, which makes sure they can be picked%0A// up by querySelectorAll later%0Afunction wrapTextNodes (view) %7B%0A  if (view.hasChildNodes()) %7B%0A    let nodes = view.childNodes%0A    for (let i = 0; i %3C nodes.length; i++) %7B%0A      let node = nodes%5Bi%5D%0A      if (node.nodeType == 3) %7B%0A        let span = document.createElement('span')%0A        span.innerText = node.textContent%0A        node.parentElement.insertBefore(span, node)%0A        node.parentElement.removeChild(node)%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A%0A
 export d
@@ -656,32 +656,55 @@
 ToHTML (view) %7B%0A
+  wrapTextNodes(view)%0A%0A
   if (view.child
@@ -774,28 +774,28 @@
 l(view.inner
-HTML
+Text
 )%0A  %7D else i
@@ -833,20 +833,23 @@
  let all
-Node
+Element
 s = view
@@ -865,18 +865,16 @@
 ectorAll
-  
 ('*')%0A  
@@ -892,23 +892,25 @@
 i = 
--1, l = allNode
+0; i %3C allElement
 s.le
@@ -919,16 +919,11 @@
 th; 
+i
 ++
-i %3C l;
 ) %7B%0A
@@ -931,28 +931,31 @@
      if (all
-Node
+Element
 s%5Bi%5D.childEl
@@ -984,20 +984,23 @@
      all
-Node
+Element
 s%5Bi%5D.inn
@@ -1034,20 +1034,23 @@
 html(all
-Node
+Element
 s%5Bi%5D.inn
@@ -1075,16 +1075,17 @@
   %7D%0A  %7D%0A
+%0A
   return

fix coloring in legacy console again