<commit_before>//Make configurable from docType??
//Set in option
var isXHTML = false;

//List from node-htmlparser
var singleTags = {
    area: 1,
    base: 1,
    basefont: 1,
    br: 1,
    col: 1,
    frame: 1,
    hr: 1,
    img: 1,
    input: 1,
    isindex: 1,
    link: 1,
    meta: 1,
    param: 1,
    embed: 1
};

var expr = {
  upperCaseChars: /([A-Z])/g,
  breakBetweenTags: /(<(\/?\w+).*?>)(?=<(?!\/\2))/gi,
  singleTag: (function() {
      var tags = [];
      for (var i in singleTags) {
          tags.push(i);
      }
      return new RegExp('<' + tags.join('|<'), 'i');
  })()
};

var uncanon = function(str, letter) {
    return '-' + letter.toLowerCase();
};

var HTMLEncode = require('./htmlencoding').HTMLEncode;

var styleIgnore = { 
    top: 1,
    left: 1,
    length : 1,
    _importants : 1
};

exports.stringifyElement = function stringifyElement(element) {
    //sys.puts('Stringify HTML for: ' + element);
    var tagName = element.tagName.toLowerCase(),
    ret = {
        start: "<" + tagName,
        end:''
    }, attributes = [], i,
    attribute = null;

    //sys.puts('Checking Attributes: ' + element._attributes.length);
    //sys.puts(sys.inspect(element));
    if (element.attributes.length) {
        ret.start += " ";
        for (i = 0; i<element.attributes.length; i++) {
            attribute = element.attributes.item(i);
            attributes.push(attribute.name + '="' + 
                            HTMLEncode(attribute.nodeValue) + '"');
        }
    }
    ret.start += attributes.join(" ");

    if (element.style) {
      var
      styleAttrs = [],
      keys = Object.keys(element.style),
      i, key,
      l=keys.length;
      for (i=0; i<l; i++) {
        key   = keys[i];
        value =  element.style[key];

        if (!styleIgnore[key] && typeof value !== 'function') {
          var use = true;
          if (i === 'position' && value === 'static') {
            use = false;
          }
          if (element.style[i] === '') {
            use = false;
          }
          if (use) {
            styleAttrs.push(key.replace(expr.upperCaseChars, uncanon) + ': ' + 
                    HTMLEncode(value));
          }
        }
      }
      if (styleAttrs.length) {
        ret.start += ' style="' + styleAttrs.join('; ') + '"';
      }
    }

    if (singleTags[tagName]) {
      if (isXHTML) {<commit_msg>domtohtml, stringifyElement: Simplified and fixed the serialization code for the style attribute. Closes #230. Closes #260.<commit_after>//Make configurable from docType??
//Set in option
var isXHTML = false;

//List from node-htmlparser
var singleTags = {
    area: 1,
    base: 1,
    basefont: 1,
    br: 1,
    col: 1,
    frame: 1,
    hr: 1,
    img: 1,
    input: 1,
    isindex: 1,
    link: 1,
    meta: 1,
    param: 1,
    embed: 1
};

var expr = {
  upperCaseChars: /([A-Z])/g,
  breakBetweenTags: /(<(\/?\w+).*?>)(?=<(?!\/\2))/gi,
  singleTag: (function() {
      var tags = [];
      for (var i in singleTags) {
          tags.push(i);
      }
      return new RegExp('<' + tags.join('|<'), 'i');
  })()
};

var uncanon = function(str, letter) {
    return '-' + letter.toLowerCase();
};

var HTMLEncode = require('./htmlencoding').HTMLEncode;

var styleIgnore = { 
    top: 1,
    left: 1,
    length : 1,
    _importants : 1
};

exports.stringifyElement = function stringifyElement(element) {
    //sys.puts('Stringify HTML for: ' + element);
    var tagName = element.tagName.toLowerCase(),
    ret = {
        start: "<" + tagName,
        end:''
    }, attributes = [], i,
    attribute = null;

    //sys.puts('Checking Attributes: ' + element._attributes.length);
    //sys.puts(sys.inspect(element));
    if (element.attributes.length) {
        ret.start += " ";
        for (i = 0; i<element.attributes.length; i++) {
            attribute = element.attributes.item(i);
            attributes.push(attribute.name + '="' + 
                            HTMLEncode(attribute.nodeValue) + '"');
        }
    }
    ret.start += attributes.join(" ");

    if (element.style) {
      var
      styleAttrs = [],
      keys = Object.keys(element.style),
      i, key, value,
      l=keys.length;
      for (i=0; i<l; i++) {
        key   = keys[i];
        value =  element.style[key];

        if (!styleIgnore[key] &&
            typeof value !== 'function' &&
            !/^\d+$/.test(key) && // Skip the integral keys that specify the order of the CSS properties
            (key !== 'position' || value !== 'static') &&
            element.style[i] !== '') {

            styleAttrs.push(key.replace(expr.upperCaseChars, uncanon) + ': ' +
                            HTMLEncode(value));
        }
      }
      if (styleAttrs.length) {
        ret.start += ' style="' + styleAttrs.join('; ') + '"';
      }
    }

    if (singleTags[tagName]) {
      if (isXHTML) {
{'fraction_non_alphanumeric': 0.17430626927029805, 'fraction_numerical': 0.00986639260020555, 'mean_word_length': 1.9437386569872959, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '495920', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1616, 'n_words': 356}