Convert html tags to html entites
@param str
@returns {XML|string|*|void}
434625
function toHtmlEntities(str) {
        str = str || '';
        return str.replace(/./gm, function(s) {
            return "&#" + s.charCodeAt(0) + ";";
        });
    }
1117772
def to_xml_string(str = '')
      str << '<?xml version="1.0" encoding="UTF-8"?>'
      str << ('<Types xmlns="' << XML_NS_T << '">')
      each { |type| type.to_xml_string(str) }
      str << '</Types>'
    end
793546
function HTMLOfENML(text, resources){

    resources = resources || [];

    var resource_map = {}
    resources.forEach(function(resource){

      var hex = [].map.call( resource.data.bodyHash, 
        function(v) { str = v.toString(16); 
        return str.length < 2 ? "0" + str : str;  }).join("");

      resource_map[hex] = resource;
    })

    var writer = new XMLWriter();
    var parser = new SaxParser(function(cb) {

      var mediaTagStarted = false;
      var linkTagStarted = false;
      var linkTitle;

      cb.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) {

        if(elem == 'en-note'){
          writer.startElement('html');
          writer.startElement('head');

          writer.startElement('meta');
          writer.writeAttribute('http-equiv', 'Content-Type');
          writer.writeAttribute('content', 'text/html; charset=UTF-8');
          writer.endElement();

          writer.endElement();

          writer.startElement('body');
          if(!(attrs && attrs[0] && attrs[0][0] && attrs[0][0] === 'style'))
            writer.writeAttribute('style', 'word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;');
        } else if(elem == 'en-todo'){

          writer.startElement('input');
          writer.writeAttribute('type', 'checkbox');

        } else if(elem == 'en-media'){

          var type = null;
          var hash = null;
          var width = 0;
          var height = 0;

          if(attrs) attrs.forEach(function(attr) {
            if(attr[0] == 'type') type = attr[1];
            if(attr[0] == 'hash') hash = attr[1];
            if(attr[0] == 'width') width = attr[1];
            if(attr[0] == 'height') height = attr[1];
          });

          var resource = resource_map[hash];
          
          if(!resource) return;
          var resourceTitle = resource.title || '';
          
          if(type.match('image')) {

            writer.startElement('img');
            writer.writeAttribute('title', resourceTitle);

          } else if(type.match('audio')) {
            
            
            writer.writeElement('p', resourceTitle);
            writer.startElement('audio');
            writer.writeAttribute('controls', '');
            writer.text('Your browser does not support the audio tag.');
            writer.startElement('source');
            mediaTagStarted = true;

          } else if(type.match('video')) {
            writer.writeElement('p', resourceTitle);
            writer.startElement('video');
            writer.writeAttribute('controls', '');
            writer.text('Your browser does not support the video tag.');
            writer.startElement('source');
            mediaTagStarted = true;
          } else {
            writer.startElement('a');
            linkTagStarted = true;
            linkTitle = resourceTitle;
          }
          
          if(resource.data.body) {
            var b64encoded = base64ArrayBuffer(resource.data.body);
            var src = 'data:'+type+';base64,'+b64encoded;
            writer.writeAttribute('src', src)
          }

          if(width) writer.writeAttribute ('width', width);
          if(height) writer.writeAttribute('height', height);

        } else {
          writer.startElement(elem);
        }

        if(attrs) attrs.forEach(function(attr) {
          writer.writeAttribute(attr[0], attr[1]);
        });

      });
      cb.onEndElementNS(function(elem, prefix, uri) {

        if(elem == 'en-note'){
          writer.endElement(); //body
          writer.endElement(); //html
        }
        else if(elem == 'en-todo'){

        }
        else if(elem == 'en-media'){
          if(mediaTagStarted) {
            writer.endElement(); // source
            writer.endElement(); // audio or video
            writer.writeElement('br', '');
            mediaTagStarted = false;

          } else if(linkTagStarted) {
            writer.text(linkTitle);
            writer.endElement(); // a
            linkTagStarted = false;

          } else {
            writer.endElement();
          }

        } else {

          writer.endElement();
        }
      });
      cb.onCharacters(function(chars) {
        writer.text(chars);
      });

    });

    parser.parseString(text);
    return writer.toString();

  }
519977
function (str) {
    var lit = this.ast_stringify(t.stringLiteral(str));
    var ast = this.ast_buffer(lit);
    return ast;
  }
767556
function(html) {
       return html.toString()
         .replace(/&/gmi, '&amp;')
         .replace(/"/gmi, '&quot;')
         .replace(/>/gmi, '&gt;')
         .replace(/</gmi, '&lt;')
     }
558329
function htmlDecode(str) {
  if (typeof str === 'string' && str.length === 0) return;

  let s = str.replace(/&amp;/g, '&');

  return s.replace(/&lt;/g, '<')
        .replace(/&gt;/g, '>')
        .replace(/&#39;/g, '\'')
        .replace(/&nbsp;/g, ' ')
        .replace(/&quot;/g, '"')
        .replace(/<br>/g, '\\n');
}
77827
function parseStringAttrs(templates, context) {
  var stringAttrs = '';
  var toString = new ToString(true, true);
  for (var i = 0; i < templates.length; i++) {
    toString.clear();
    render(toString, templates[i], context);
    stringAttrs += ' ' + toString.getOutput() + ' ';
  }
  if (whitespaceOnlyRegex.test(stringAttrs)) {
    return null;
  }
  var node = htmlParser('<div ' + stringAttrs + '></div>');
  return node.properties.attributes;
}
196917
function HTML(strings, ...values) {
  var dummy = document.createElement('div');
  var fragment = document.createDocumentFragment();
  dummy.innerHTML = compose(strings, ...values);
  forEach.call(dummy.childNodes, appendChild, fragment);
  return fragment;
}
539634
function amf0encXmlDoc(str) { // Essentially it is the same as string
    var buf = new Buffer(3);
    buf.writeUInt8(0x0F, 0);
    buf.writeUInt16BE(str.length, 1);
    return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
491151
def html_to_dom(html, default_encoding=DEFAULT_ENCODING, encoding=None, errors=DEFAULT_ENC_ERRORS):
    """"""
    if isinstance(html, unicode):
        decoded_html = html
        # encode HTML for case it's XML with encoding declaration
        forced_encoding = encoding if encoding else default_encoding
        html = html.encode(forced_encoding, errors)
    else:
        decoded_html = decode_html(html, default_encoding, encoding, errors)

    try:
        dom = lxml.html.fromstring(decoded_html, parser=lxml.html.HTMLParser())
    except ValueError:
        # Unicode strings with encoding declaration are not supported.
        # for XHTML files with encoding declaration, use the declared encoding
        dom = lxml.html.fromstring(html, parser=lxml.html.HTMLParser())

    return dom
1319814
public static String filterXML(String str) {
    String s = str;       
    if (s.contains("<")) { // don't run slow regex unless we have to
      s = XML_COMMENT_PATTERN.matcher(s).replaceAll(" ");
      s = XML_PATTERN.matcher(s).replaceAll("");
    }
    return s;
  }
208910
public void parseHtmlData(PrintWriter out, String str)
    {
        int iCurrentParsePos = 0;
        int iCurrentOutputPos = 0;
        int iStartTag, iStartVelocity;
        while (true)
        { // Done
        	iStartTag = str.indexOf('<', iCurrentParsePos);
        	iStartVelocity = str.indexOf("${", iCurrentParsePos);
        	if ((iStartTag == -1) && (iStartVelocity == -1))
    			break;	// Done
        	String strTag, strParams, strData;
        	int iNextParam, iEndCloseTag;
    		if ((iStartVelocity == -1) || (iStartVelocity > iStartTag))
    		{	// xml format param
	            iCurrentParsePos = iStartTag + 1;
	            if (iCurrentParsePos == str.length())
	                break;
	            if (str.charAt(iStartTag + 1) == '/') // Don't process end tags
	                continue;
	            int iEndTag = str.indexOf(' ', iStartTag);
	            int iEndParam = str.indexOf('>', iStartTag);
	            if (iEndParam == -1)
	                break;      // poorly formed XML
	            int iNextVelocity = str.indexOf("${", iCurrentParsePos);
	            if (iNextVelocity != -1) if (iNextVelocity < iEndParam)
	                continue;   // This handles the case: <IMG=${image}>   (used internally)
	            iNextParam = str.indexOf('<', iCurrentParsePos);
	            if (iNextParam != -1) if (iNextParam < iEndParam)
	                continue;   // This handles the case: <IMG=<image/>>   (used internally)
	            if (iNextVelocity != -1) if (iNextVelocity < iNextParam)
	            	iNextParam = iNextVelocity;
	            iEndCloseTag = iEndParam;
	            if (str.charAt(iEndParam - 1) == '/')
	                iEndParam = iEndParam - 1;
	            if ((iEndTag == -1) || (iEndTag > iEndParam))
	                iEndTag = iEndParam;
	            strTag = str.substring(iStartTag + 1, iEndTag);
	            strParams = null;
	            if (iEndTag != iEndParam)
	                strParams = str.substring(iEndTag + 1, iEndParam);
	            strData = null;
	            int iStartCloseTag = -1;
	            
	            if (iCurrentOutputPos != iStartTag)
	                out.print(str.substring(iCurrentOutputPos, iStartTag));     // Print everything up to the start of the tag.
	            iCurrentOutputPos = iStartTag;
	            
	            if (str.charAt(iEndCloseTag) != '/')
	            {   // Find the end tag (if start tag doesn't end in '/')
	                iStartCloseTag = str.indexOf("</" + strTag + '>', iEndTag);
	                if (iStartCloseTag > iEndTag)
	                {
	                    iEndCloseTag = iStartCloseTag + strTag.length() + 2;
	                    strData = str.substring(iEndParam + 1, iStartCloseTag);
	                }
	            }
        	}
    		else
    		{	// Velocity format param
    			strParams = null;
    			strData = null;
    			
	            iCurrentParsePos = iStartTag + 2;	// ${
	            if (iCurrentParsePos == str.length())
	                break;
	            iEndCloseTag = str.indexOf('}', iStartTag);
	            if (iEndCloseTag == -1)
	                break;      // poorly formed Velocity tag
    			strTag = str.substring(iStartTag + 2, iEndCloseTag);

	            int iNextVelocity = str.indexOf("${", iCurrentParsePos);
	            iNextParam = str.indexOf('<', iCurrentParsePos);
	            if (iNextVelocity != -1) if (iNextVelocity < iNextParam)
	            	iNextParam = iNextVelocity;
    		}

            // Now, I have the tag, params, and data for this tag
            boolean bProcessed = this.parseHtmlTag(out, strTag, strParams, strData);
            
            if (!bProcessed)
            {
                out.print(str.substring(iCurrentOutputPos, iNextParam));     // It wasn't processed, so output it.
                iCurrentOutputPos = iNextParam;
            }
            else
                iCurrentOutputPos = iEndCloseTag + 1;
            iCurrentParsePos = iCurrentOutputPos;
        }
        iStartTag = str.length();
        if (iCurrentOutputPos != iStartTag)
            out.println(str.substring(iCurrentOutputPos, iStartTag));
    }
477691
function parse (str, options) {
  if (typeof str !== 'string') throw new TypeError('str is required!');

  var splitData = split(str);
  var raw = splitData.data;

  if (!raw) return { _content: str };

  var data;

  data = parseYAML(raw, options);

  if (!data) return { _content: str };

  data._content = splitData.content;

  return data;
}
1138812
function _parseXml( xmlStr ) {
    let doc;

    return new Promise( ( resolve, reject ) => {
        try {
            doc = libxmljs.parseXml( xmlStr );
            resolve( doc );
        } catch ( e ) {
            reject( e );
        }
    } );
}
280108
def to_xml_string(str = '')
      valid = RichTextRun::INLINE_STYLES
      data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }]
      data = data.select { |key, value| valid.include?(key) && !value.nil? }

      str << '<r><rPr>'
      data.keys.each do |key|
        case key
        when :font_name
          str << ('<rFont val="' << font_name << '"/>')
        when :color
          str << data[key].to_xml_string
        else
          str << ('<' << key.to_s << ' val="' << xml_value(data[key]) << '"/>')
        end
      end
      clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
      str << ('</rPr><t>' << clean_value << '</t></r>')
    end
999185
function htmlStringify(obj, fromRecur) {

	var tag = (fromRecur) ? 'span' : 'div';
	var nextLevel = (fromRecur || 0) + 1;
	
	// strings
	if (typeof obj == 'string') {
		return '<' + tag + ' style="color: #0e4889; cursor: default;">"' + obj + '"</' + tag + '>';
	}
	// booleans, null and undefined
	else if (typeof obj == 'boolean' || obj === null || obj === undefined) {
		return '<' + tag + '><em style="color: #06624b; cursor: default;">' + obj + '</em></' + tag + '>';
	}
	// numbers
	else if (typeof obj == 'number') {
		return '<' + tag + ' style="color: #ca000a; cursor: default;">' + obj + '</' + tag + '>';
	}
	// dates
	else if (Object.prototype.toString.call(obj) == '[object Date]') {
		return '<' + tag + ' style="color: #009f7b; cursor: default;">' + obj + '</' + tag + '>';
	}
	// arrays
	else if (Array.isArray(obj)) {
		
		var rtn = '<' + tag + ' style="color: #666; cursor: default;">Array: [';
		
		if (!obj.length) {
			return rtn + ']</' + tag + '>';
		}
		
		rtn += '</' + tag + '><div style="padding-left: 20px;">';
		
		for (var i = 0; i < obj.length; i++) {
			rtn += '<span></span>' + htmlStringify(obj[i], nextLevel); // give the DOM structure has as many elements as an object, for collapse behaviour
			if (i < obj.length - 1) {
				rtn += ', <br>';
			}
		}
	
		return rtn + '</div><' + tag + ' style="color: #666">]</' + tag + '>';
		
	}
	// objects
	else if (obj && typeof obj == 'object') {
		
		var rtn = '',
			len = Object.keys(obj).length;
	
		if (fromRecur && !len) {
			return '<' + tag + ' style="color: #999; cursor: default;">Object: {}</' + tag + '>';
		}
		
		if (fromRecur) {
			rtn += '<' + tag + ' style="color: #0b89b6">Object: {</' + tag + '><div class="_stringify_recur _stringify_recur_level_' + fromRecur + '" style="padding-left: 20px;">';
		}
		
		for (var key in obj) {
			if (typeof obj[key] != 'function') {
				rtn += '<div><span style="padding-right: 5px; cursor: default;">' +key + ':</span>' + htmlStringify(obj[key], nextLevel) + '</div>';
			}
		}
		
		if (fromRecur) {
			rtn += '</div><' + tag + ' style="color: #0b89b6; cursor: default;">}</' + tag + '>';
		}
		
		return rtn;
		
	}

	return '';

}
520823
function htmlToComponent(str, tags, opts) {
  var keys = objectKeys(tags);
  var props = opts.props || {};
  var preserveAttributes = opts.preserveAttributes || [];
  var tagAttributes = [];
  var reactTags={};
  var reactKeys=[];
  var key;
  for(var i = 0; i<keys.length; i++) {
    key = "AB"+Math.random().toString(36).substring(2);
    if(typeof tags[keys[i]] !== "function") {
      if(typeof tags[keys[i]].slice !== "function") continue;
      tagAttributes = tags[keys[i]].slice(0,-1);
      reactTags[key] = tags[keys[i]].slice(-1)[0];
    }
    else
      reactTags[key] = tags[keys[i]];

    reactKeys.push(key);

    str = str
      .replace(new RegExp("(<\/?)"+keys[i]+"(?:[^>\"']|\".*\"|'.*')*>", "ig"), function(match, start){
        // find/replace spell-save attributes within tag to restore capitals
        if(start !== "</")
          for(var a=0; a<tagAttributes.length; a++)
            match = replaceAttribute(match, tagAttributes[a], tagAttributes[a]);

        // replace key
        return match
          .replace(new RegExp(start+keys[i]+"(\\s|>)", "i"), start+key+"$1");
      });
  }

  // remove/disable html comments
  str = str.replace(/<!--|-->/g,"")

  // find/replace global spell-save attributes to restore capitals
  var attributes = preserveReactAttributes.concat(preserveAttributes);
  for(var i=0; i<attributes.length; i++) 
    str = replaceAttribute(str, attributes[i], attributes[i]);
 
  var jsx = htmlToJsx(str);

  // replace props variables {key} with corrected variables {props['key']}
  for(var key in props) {
    jsx = jsx
      .replace(new RegExp("(\{"+key+"\})","g"),"{props['"+key+"']}");
  }
  
  var component = ReactTransform(jsx).code;
  
  // replace component variables (ComponentName) with corrected variables (tags['ComponentName'])
  for(var i=0; i<reactKeys.length; i++) {
    component = component
      .replace(new RegExp(reactKeys[i],"g"), "reactTags['"+reactKeys[i]+"']"); 
  }

  return eval(component);
}