Prepare html parser logic
- Observes for paste and drop
170439
function() {
      var that = this,
          oldHtml,
          cleanHtml;

      if (wysihtml5.browser.supportsModenPaste()) {
        this.on("paste:composer", function(event) {
          event.preventDefault();
          oldHtml = wysihtml5.dom.getPastedHtml(event);
          if (oldHtml) {
            that._cleanAndPaste(oldHtml);
          }
        });

      } else {
        this.on("beforepaste:composer", function(event) {
          event.preventDefault();
          wysihtml5.dom.getPastedHtmlWithDiv(that.composer, function(pastedHTML) {
            if (pastedHTML) {
              that._cleanAndPaste(pastedHTML);
            }
          });
        });

      }
    }
216660
function addParserEvents(parser) {
  parser.onopentag = parser_opentag;
  parser.onclosetag = parser_closetag;
  parser.ontext = parser_text;
  parser.oncdata = parser_cdata;
}
115883
function() {

      var x, y, z, arr, edits, isEditable, configs, isConfig, el, html,li, parent, els, isDefault, removeElement, element, modal, body, attr, div, label, control, option, menuItem, els, text, block;


      // clean pasted text, #ref: http://bit.ly/1Tr8IR3
      document.addEventListener('paste', function(e) {

        if(e.target.nodeName == 'TEXTAREA') {
          // do nothing
        }
        else {
          // cancel paste
          e.preventDefault();

          // get text representation of clipboard
          var text = e.clipboardData.getData("text/plain");

          // insert text manually
          document.execCommand("insertHTML", false, text);
        }

      });


      // get contentEditable elements
      arr = document.querySelectorAll('body');

      for (x = 0; x < arr.length; x += 1) {

        // delegate CLICK, FOCUS event
        ['click', 'focus'].forEach(function(e) {

          arr[x].addEventListener(e, function(e) {

            if (e.target.hasAttribute('hashedit-element')) {
              element = e.target;

              // get value of text node
              var text = hashedit.getTextNodeValue(element);

              // if text is set to "Tap to update" select all the text
              if(text === hashedit.i18n('Tap to update')) {
                document.execCommand('selectAll', false, null);
              }

            }
            else {
              element = hashedit.findParentBySelector(e.target, '[hashedit-element]');
            }

            // remove all current elements
            els = document.querySelectorAll('[current-hashedit-element]');

            for (y = 0; y < els.length; y += 1) {
              els[y].removeAttribute('current-hashedit-element');
            }

            // set current element
            if (element) {
              element.setAttribute('current-hashedit-element', 'true');
            }

            // check for remove element
            if (e.target.matches('.hashedit-remove')  || hashedit.findParentBySelector(e.target, '.hashedit-remove') !== null) {
              element.remove();
            }
            // check for properties element
            else if (e.target.matches('.hashedit-properties')  ||  hashedit.findParentBySelector(e.target, '.hashedit-properties') !== null) {

              hashedit.current.node = element;

              isDefault = true;

              // get menuItem
              menuItem = null;

              // see if the element matches a plugin selector
              for (x = 0; x < hashedit.menu.length; x += 1) {

                if (element.matches(hashedit.menu[x].selector)) {

                  menuItem = hashedit.menu[x];

                  if (hashedit.menu[x].configure) {
                    isDefault = false;
                    hashedit.menu[x].configure();
                  }

                }

              }

              if (isDefault === true) {

                modal = document.getElementById('hashedit-element-settings-modal');
                body = modal.querySelector('.hashedit-modal-body');

                // remove existing custom attributes
                els = body.querySelectorAll('.hashedit-custom-attr');

                for(y=0; y<els.length; y++) {
                  els[y].parentNode.removeChild(els[y]);
                }

                // setup custom attributes
                if(menuItem != null) {

                  if(menuItem.attributes) {

                    for(y=0; y<menuItem.attributes.length; y++){

                      attr = menuItem.attributes[y];

                      div = document.createElement('div');
                      div.setAttribute('class', 'hashedit-custom-attr');

                      label = document.createElement('label');
                      label.innerHTML = attr.label;

                      div.appendChild(label);

                      if(attr.type == 'text'){
                        control = document.createElement('input');
                        control.setAttribute('type', 'text');
                        control.setAttribute('data-model', 'node.' + attr.attr);
                        control.setAttribute('name', 'attr');

                        div.appendChild(control);
                      }

                      if(attr.type == 'select'){
                        control = document.createElement('select');
                        control.setAttribute('data-model', 'node.' + attr.attr);
                        control.setAttribute('name', 'attr');

                        // create options
                        if(attr.values != null) {

                          for(z=0; z<attr.values.length; z++){

                            option = document.createElement('option');

                            // determine if hashed array
                            if(attr.values[z].text) {
                              option.setAttribute('value', attr.values[z].value);
                              option.innerHTML = attr.values[z].text;
                            }
                            else {
                              option.setAttribute('value', attr.values[z]);
                              option.innerHTML = attr.values[z];
                            }

                            control.appendChild(option);
                          }

                        }

                        div.appendChild(control);

                      }

                      body.appendChild(div);

                    }


                  }

                }

                // bind
                hashedit.bind();

                // show modal
                modal.setAttribute('visible', 'true');

              }

            }
            // add block
            else if (e.target.matches('.hashedit-block-add') || hashedit.findParentBySelector(e.target, '.hashedit-block-add') !== null) {

              block = hashedit.findParentBySelector(e.target, '[hashedit-block]');

              if(block !== null) {
                hashedit.showLayoutDialog(block);
              }

            }
            // properites block
            else if (e.target.matches('.hashedit-block-properties') || hashedit.findParentBySelector(e.target, '.hashedit-block-properties') !== null) {

              block = hashedit.findParentBySelector(e.target, '[hashedit-block]');

              if(block !== null) {

                var modal = document.getElementById('hashedit-block-settings-modal');

                // show modal
                modal.setAttribute('visible', 'true');

                hashedit.current.node = block;
                hashedit.bind();

              }

            }
            // move block up
            else if (e.target.matches('.hashedit-block-up') ||  hashedit.findParentBySelector(e.target, '.hashedit-block-up') !== null) {

              block = hashedit.findParentBySelector(e.target, '[hashedit-block]');

              if(block.previousElementSibling != null) {

                if(block.previousElementSibling.hasAttribute('hashedit-block') === true) {
                  block.parentNode.insertBefore(block, block.previousElementSibling);
                }

              }

              hashedit.setupBlocks();

            }
            // move block down
            else if (e.target.matches('.hashedit-block-down') ||  hashedit.findParentBySelector(e.target, '.hashedit-block-down') !== null) {

              block = hashedit.findParentBySelector(e.target, '[hashedit-block]');

              if(block.nextElementSibling != null) {

                if(block.nextElementSibling.hasAttribute('hashedit-block') === true) {
                  block.nextElementSibling.parentNode.insertBefore(block.nextElementSibling, block);
                }

              }

              hashedit.setupBlocks();

            }
            // remove block
            else if (e.target.matches('.hashedit-block-remove') ||  hashedit.findParentBySelector(e.target, '.hashedit-block-remove') !== null) {

              block = hashedit.findParentBySelector(e.target, '[hashedit-block]');
              block.remove();

              hashedit.setupBlocks();

            }
            // remove block
            else if (hashedit.findParentBySelector(e.target, '.hashedit-block-duplicate') !== null) {

              block = hashedit.findParentBySelector(e.target, '[hashedit-block]');

              hashedit.duplicateBlock(block, 'before');

              hashedit.setupBlocks();

            }
            // handle links
            else if (e.target.nodeName == 'A') {

                // hide .hashedit-config, .hashedit-modal
                edits = document.querySelectorAll('[hashedit]');

                // determines whether the element is a configuration
                isEditable = false;

                for (x = 0; x < edits.length; x += 1) {

                  if (edits[x].contains(e.target) === true) {
                    isEditable = true;
                  }

                }

                if (isEditable) {
                  hashedit.showLinkDialog();
                }
            }
            else if (e.target.nodeName == 'IMG') {
                hashedit.current.node = e.target;
                hashedit.current.image = e.target;

                // hide .hashedit-config, .hashedit-modal
                edits = document.querySelectorAll('[hashedit]');

                // determines whether the element is a configuration
                isEditable = false;

                for (x = 0; x < edits.length; x += 1) {

                  if (edits[x].contains(e.target) === true) {
                    isEditable = true;
                  }

                }

                if (isEditable) {
                  hashedit.showImageDialog();
                }
            }
            else if (e.target.hasAttribute('contentEditable')) {

              // shows the text options
              hashedit.showTextOptions(e.target);

            }
            else if (e.target.parentNode.hasAttribute('contentEditable') && e.target.parentNode) {

              // shows the text options
              hashedit.showTextOptions(e.target);

            }
            else if (e.target.className == 'dz-hidden-input') {
              // do nothing
            }
            else {
              // hide .hashedit-config, .hashedit-modal
              configs = document.querySelectorAll(
                '.hashedit-config, .hashedit-modal, .hashedit-menu'
              );

              // determines whether the element is a configuration
              isConfig = false;

              for (x = 0; x < configs.length; x += 1) {

                if (configs[x].contains(e.target) === true) {
                  isConfig = true;
                }

              }

              // hide if not in config
              if (isConfig === false) {

                for (x = 0; x < configs.length; x += 1) {
                  configs[x].removeAttribute('visible');
                }

              }
            }

          });

        });


        // delegate INPUT event
        ['input'].forEach(function(e) {
          arr[x].addEventListener(e, function(e) {

            if (e.target.hasAttribute('contentEditable')) {

              el = e.target;

              while (el !== null) {

                var node = el.childNodes[0];

                if (hashedit.debug === true) {
                  console.log('input event');
                  console.log(el.nodeName);
                }

                // get value of text node
                var text = hashedit.getTextNodeValue(el);

                // if text is blank and the element has only one child node, add "Tap to update" to prevent the editor from breaking
                if(text === '' && el.childNodes.length == 1) {
                  text = document.createTextNode(hashedit.i18n('Tap to update'));
                  el.insertBefore(text, el.firstChild);
                  document.execCommand('selectAll', false, null);
                }

                html = el.innerHTML;

                // strip out &nbsps
                html = hashedit.replaceAll(html, '&nbsp;', ' ');

                // trim
                html = html.trim();

                // set to null
                el = null;
              }

            }


          });

        });

        // delegate INPUT event
        ['keydown'].forEach(function(e) {
          arr[x].addEventListener(e, function(e) {

            if (e.target.hasAttribute('contentEditable')) {

              el = e.target;

              // ENTER key
              if (e.keyCode === 13) {

                if (el.nodeName == 'LI') {

                  // create LI
                  li = document.createElement('li');
                  li.setAttribute('contentEditable', true);

                  // append LI
                  el.parentNode.appendChild(li);

                  el.parentNode.lastChild.focus();

                  e.preventDefault();
                  e.stopPropagation();

                }
                else if (el.nodeName == 'P') {

                  var node = hashedit.append('<p>' + hashedit.i18n('Tap to update') + '</p>');

                  hashedit.current.node = node;


                  e.preventDefault();
                  e.stopPropagation();

                }

              }

              // DELETE key
              if (e.keyCode === 8) {

                if (el.nodeName == 'LI') {

                  if (el.innerHTML === '') {

                    if (el.previousSibling !== null) {

                      parent = el.parentNode;

                      el.remove();

                      parent.lastChild.focus();
                    }

                    e.preventDefault();
                    e.stopPropagation();
                  }

                } // end LI

              }

            }


          });

        });

      }

    }
726218
function before_html_mode(t,value,arg3,arg4) {
    var elt;
    switch(t) {
    case 1: // TEXT
      value = value.replace(LEADINGWS, ""); // Ignore spaces
      if (value.length === 0) return; // Are we done?
      break; // Handle anything non-space text below
    case 5: // DOCTYPE
      /* ignore the token */
      return;
    case 4: // COMMENT
      doc._appendChild(doc.createComment(value));
      return;
    case 2: // TAG
      if (value === "html") {
        elt = createHTMLElt(doc, value, arg3);
        stack.push(elt);
        doc.appendChild(elt);
        // XXX: handle application cache here
        parser = before_head_mode;
        return;
      }
      break;
    case 3: // ENDTAG
      switch(value) {
      case "html":
      case "head":
      case "body":
      case "br":
        break;  // fall through on these
      default:
        return; // ignore most end tags
      }
    }

    // Anything that didn't get handled above is handled like this:
    elt = createHTMLElt(doc, "html", null);
    stack.push(elt);
    doc.appendChild(elt);
    // XXX: handle application cache here
    parser = before_head_mode;
    parser(t,value,arg3,arg4);
  }
163879
def html_parser(self, scode, *args):
        
        allow_method = ('text', 'html', 'xml')
        css_path, method = args
        assert method in allow_method or method.startswith(
            '@'), 'method allow: %s or @attr' % allow_method
        result = self.ensure_list(
            self._fromstring(scode,
                             parser=self._html_parser).cssselect(css_path))
        if method.startswith('@'):
            result = [item.get(method[1:]) for item in result]
        else:
            result = [
                self._tostring(
                    item, method=method, with_tail=0, encoding='unicode')
                for item in result
            ]
        return result
519627
function parseCss (ctx, done) {
  var result
  try {
    result = postcss()
      .process(ctx.src, {
        map: {
          sourcesContent: true,
          annotation: false,
          prev: ctx.map
        },
        from: ctx.filename
      })
    ctx.src = result.css
    ctx.map = result.map.toJSON()
    done(null, ctx)
  } catch (e) {
    var msg = e.message
    var ext = extname(ctx.filename).slice(1).toLowerCase()
    if (ext !== 'css') {
      msg += ' (Try to use appropriate parser for ' + ext + ')'
    }
    done(new Error(msg))
  }
}
1201035
function HTMLReactParser(html, options) {
  if (typeof html !== 'string') {
    throw new TypeError('First argument must be a string');
  }
  return domToReact(htmlToDOM(html, domParserOptions), options);
}
467980
protected void prepDocument() {
        /**
         * In some cases a body element can't be found (if the HTML is totally
         * hosed for example) so we create a new body node and append it to the
         * document.
         */
        if (mDocument.body() == null) {
            mDocument.appendElement("body");
        }

        /* Remove all scripts */
        Elements elementsToRemove = mDocument.getElementsByTag("script");
        for (Element script : elementsToRemove) {
            script.remove();
        }

        /* Remove all stylesheets */
        elementsToRemove = getElementsByTag(mDocument.head(), "link");
        for (Element styleSheet : elementsToRemove) {
            if ("stylesheet".equalsIgnoreCase(styleSheet.attr("rel"))) {
                styleSheet.remove();
            }
        }

        /* Remove all style tags in head */
        elementsToRemove = mDocument.getElementsByTag("style");
        for (Element styleTag : elementsToRemove) {
            styleTag.remove();
        }

        /* Turn all double br's into p's */
        /*
         * TODO: this is pretty costly as far as processing goes. Maybe optimize
         * later.
         */
        mDocument.body().html(
                mDocument.body().html()
                        .replaceAll(Patterns.REGEX_REPLACE_BRS, "</p><p>")
                        .replaceAll(Patterns.REGEX_REPLACE_FONTS, "<$1span>"));
    }
1293094
function markdown(preset, options) {
  var stream = through(transform, flush)
  var parser = new Remarkable(preset, options)
  var buffer = []

  function transform(chunk, encoding, done) {
    buffer.push(chunk)
    done()
  }

  function flush(done) {
    this.push(parser.render(buffer.join('\n')))
    done()
  }

  return stream
}
1050308
function makeFormBodyParser(spec) {
  const opts = spec.validate.formOptions || {};
  if (typeof opts.limit === 'undefined') {
    opts.limit = spec.validate.maxBody;
  }
  return async function parseFormBody(ctx, next) {
    if (!ctx.request.is('urlencoded')) {
      return ctx.throw(400, 'expected x-www-form-urlencoded');
    }
    ctx.request.body = ctx.request.body || await parse.form(ctx, opts);
    await next();
  };
}
675517
function prepareSelectAllHack(){if(te.selectionStart!=null){var selected=cm.somethingSelected();var extval='\u200B'+(selected?te.value:"");te.value='\u21DA';// Used to catch context-menu undo
te.value=extval;input.prevInput=selected?"":'\u200B';te.selectionStart=1;te.selectionEnd=extval.length;// Re-set this, in case some other handler touched the
// selection in the meantime.
display.selForContextMenu=cm.doc.sel;}}
1066062
protected function prepareHTMLChunk(&$html_source)
  { 
    // WARNING:
    // When modifying, test thhe following regexes on a huge page for preg_replace segfaults.
    // Be sure to set the preg-groups to "non-capture" (?:...)!
    
    // Replace <script>-sections from source, but only those without src in it.
    if ($this->ignore_document_sections & PHPCrawlerLinkSearchDocumentSections::SCRIPT_SECTIONS)
    {
      $html_source = preg_replace("#<script(?:(?!src).)*>.*(?:<\/script>|$)# Uis", "", $html_source);
      $html_source = preg_replace("#^(?:(?!<script).)*<\/script># Uis", "", $html_source);
    }
    
    // Replace HTML-comments from source
    if ($this->ignore_document_sections & PHPCrawlerLinkSearchDocumentSections::HTML_COMMENT_SECTIONS)
    {
      $html_source = preg_replace("#<\!--.*(?:-->|$)# Uis", "", $html_source);
      $html_source = preg_replace("#^(?:(?!<\!--).)*--># Uis", "", $html_source);
    }
    
    // Replace javascript-triggering attributes
    if ($this->ignore_document_sections & PHPCrawlerLinkSearchDocumentSections::JS_TRIGGERING_SECTIONS)
    {
      $html_source = preg_replace("#on[a-z]+\s*=\s*(?|\"([^\"]+)\"|'([^']+)'|([^\s><'\"]+))# Uis", "", $html_source);
    }
  }
171002
function makeCookieCutter(parser){
  var dummy = function(){};
  return function(req){
    parser(req, null, dummy);
    return req.cookies['connect.sid'];
  }
}
1373536
def _create_parser(self, html_parser, current_url):
        

        css_code = ''

        elements = html_parser.find(
            'style,link[rel="stylesheet"]'
        ).list_results()
        for element in elements:
            if element.get_tag_name() == 'STYLE':
                css_code = css_code + element.get_text_content()
            else:
                css_code = css_code + requests.get(
                    urljoin(current_url, element.get_attribute('href'))
                ).text

        self.stylesheet = tinycss.make_parser().parse_stylesheet(css_code)
1290193
function MarkdownExtra_Parser() {
	#
	# Constructor function. Initialize the parser object.
	#
		# Add extra escapable characters before parent constructor 
		# initialize the table.
		$this->escape_chars .= ':|';
		
		# Insert extra document, block, and span transformations. 
		# Parent constructor will do the sorting.
		$this->document_gamut += array(
			"doFencedCodeBlocks" => 5,
			"stripFootnotes"     => 15,
			"stripAbbreviations" => 25,
			"appendFootnotes"    => 50,
			);
		$this->block_gamut += array(
			"doFencedCodeBlocks" => 5,
			"doTables"           => 15,
			"doDefLists"         => 45,
			);
		$this->span_gamut += array(
			"doFootnotes"        => 5,
			"doAbbreviations"    => 70,
			);
		
		parent::Markdown_Parser();
	}
672294
function processHTML(cssSelectors = [], htmlDataIn = null, htmlOptionsIn = null) {

		//read html files
		if (OPTIONS.html !== '' && OPTIONS.html !== undefined && OPTIONS.special_reduce_with_html) {

			var htmlFiles = OPTIONS.html;
			tmpHTMLPaths = [];

			//check for file or files
			switch (typeof htmlFiles) {
				case 'object':
				case 'array':
						
					for (i = 0; i < htmlFiles.length; ++i) {

						getFilePaths(htmlFiles[i], ['.html','.htm']);
					}

					if (tmpHTMLPaths.length) {
						htmlFiles = tmpHTMLPaths;
					}
					break;
				case 'string':
					//formats
					htmlFiles = htmlFiles.replace(/ /g, '');

					// comma delimited list - filename1.html, filename2.html
					if (htmlFiles.indexOf(',') > -1) { 
			
						htmlFiles = htmlFiles.replace(/^\s+|\s+$/g,'').split(',');
						tmpStr = '';
						for (i = 0; i < htmlFiles.length; ++i) {

							getFilePaths(htmlFiles[i], ['.html','.htm']);

						} //end of for

						if (tmpHTMLPaths.length) {
							htmlFiles = tmpHTMLPaths;
						}

					} else {

						//string path
						getFilePaths(htmlFiles, ['.html','.htm']);

						if (tmpHTMLPaths.length) {
							htmlFiles = tmpHTMLPaths;
						}

					}

					break;
			} //end of switch

			htmlFileLocation = (htmlFiles)?htmlFiles.toString():htmlFiles;

			readHTMLFile(htmlFiles);
			CPEVENTS.on('HTML_READ_AGAIN', function(){
				//process selectors
				processHTMLSelectors(cssSelectors, htmlDataIn, htmlOptionsIn);

				//read next file
				dataHTMLIn = [];
				readHTMLFile(htmlFiles);
			});
			CPEVENTS.on('HTML_READ_END', function(){
				//process selectors
				processHTMLSelectors(cssSelectors, htmlDataIn, htmlOptionsIn);

				dataHTMLIn = [];
				CPEVENTS.emit('HTML_RESULTS_END', cssSelectors);

			});


		} //end of html files check








	}
301087
final protected function parseRow(): void
    {
        // only parse the next row if only one in buffer
        if (\count($this->bufferedRow) > 1) {
            return;
        }
        if (feof($this->file)) {
            $this->currentRow = null;

            return;
        }

        $this->currentRowEnded = false;
        // read file until row is ended
        while (!$this->currentRowEnded && !feof($this->file)) {
            $data = fread($this->file, 1024);
            xml_parse($this->parser, $data);
        }
    }