<commit_before>mdast = require 'mdast'
uuid = require 'uuid'

$ = React.createElement
defaultHTMLWrapper = React.createClass
  _update: ->
    current = @props.html
    if @_lastHtml isnt current
      @_lastHtml = current
      node = @refs.htmlWrapper.getDOMNode()
      node.contentDocument.body.innerHTML = @props.html
      node.style.height = node.contentWindow.document.body.scrollHeight + 'px'
      node.style.width  = node.contentWindow.document.body.scrollWidth  + 'px'

  componentDidUpdate: -> @_update()
  componentDidMount: -> @_update()

  render: ->
    $ 'iframe',
      ref: 'htmlWrapper'
      html: @props.html
      style:
        border: 'none'

toChildren = (node, parentKey, tableAlign = []) ->
  return (for child, i in node.children
    align = tableAlign[i]
    compile(child, parentKey+'_'+i, align))

parser = new DOMParser()
isInvalidXML = (xmlString) ->
  parsererrorNS = parser.parseFromString('INVALID', 'text/xml').getElementsByTagName("parsererror")[0].namespaceURI
  dom = parser.parseFromString(xmlString, 'text/xml')

  if dom.getElementsByTagNameNS(parsererrorNS, 'parsererror').length > 0
    throw new Error('Error parsing XML')
  return dom;

sanitize = null
compile = (node, parentKey='_start', tableAlign = null) ->
  key = parentKey+'_'+node.type

  switch node.type
    # No child
    when 'text'           then node.value
    when 'escape'         then '\\'
    when 'inlineCode'     then $ 'code', {key, className:'inlineCode'}, node.value
    when 'code'           then $ 'code', {key, className:'code'}, node.value
    when 'break'          then $ 'br', {key}
    when 'horizontalRule' then $ 'hr', {key}
    when 'image'          then $ 'img', {key, src: node.src, title: node.title, alt: node.alt}

    # Has children
    when 'root'       then $ 'div', {key}, toChildren(node, key)<commit_msg>Wrap code block in pre<commit_after>mdast = require 'mdast'
uuid = require 'uuid'

$ = React.createElement
defaultHTMLWrapper = React.createClass
  _update: ->
    current = @props.html
    if @_lastHtml isnt current
      @_lastHtml = current
      node = @refs.htmlWrapper.getDOMNode()
      node.contentDocument.body.innerHTML = @props.html
      node.style.height = node.contentWindow.document.body.scrollHeight + 'px'
      node.style.width  = node.contentWindow.document.body.scrollWidth  + 'px'

  componentDidUpdate: -> @_update()
  componentDidMount: -> @_update()

  render: ->
    $ 'iframe',
      ref: 'htmlWrapper'
      html: @props.html
      style:
        border: 'none'

toChildren = (node, parentKey, tableAlign = []) ->
  return (for child, i in node.children
    align = tableAlign[i]
    compile(child, parentKey+'_'+i, align))

parser = new DOMParser()
isInvalidXML = (xmlString) ->
  parsererrorNS = parser.parseFromString('INVALID', 'text/xml').getElementsByTagName("parsererror")[0].namespaceURI
  dom = parser.parseFromString(xmlString, 'text/xml')

  if dom.getElementsByTagNameNS(parsererrorNS, 'parsererror').length > 0
    throw new Error('Error parsing XML')
  return dom;

sanitize = null
compile = (node, parentKey='_start', tableAlign = null) ->
  key = parentKey+'_'+node.type

  switch node.type
    # No child
    when 'text'           then node.value
    when 'escape'         then '\\'
    when 'break'          then $ 'br', {key}
    when 'horizontalRule' then $ 'hr', {key}
    when 'image'          then $ 'img', {key, src: node.src, title: node.title, alt: node.alt}
    when 'inlineCode'     then $ 'code', {key, className:'inlineCode'}, node.value
    when 'code'
      $ 'pre', {key, className:'code'}, [
        $ 'code', {key: key+'-_inner-code'}, node.value
      ]

    # Has children
    when 'root'       then $ 'div', {key}, toChildren(node, key)
{'fraction_non_alphanumeric': 0.14220917822838847, 'fraction_numerical': 0.0010672358591248667, 'mean_word_length': 3.14712389380531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3344877', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1176, 'n_words': 289}