Parse a ``BeautifulSoup`` element as the given type.
768464
def parse(el, typ):
    
    if not el:
        return typ()
    txt = text(el)
    if not txt:
        return typ()
    return typ(txt)
646429
def _parse_type(value, type_func):
        
        default = type_func(0)
        if value is None:
            return default
        try:
            return type_func(value)
        except ValueError:
            return default
1241149
def parse_doc(p, pos)
      tag = p.standard_tag({:tagname => :type, :type => true, :optional => true})
      tag[:type] = curlyless_type(p) unless tag[:type]
      tag
    end
120046
def parse_at_element(
            self,
            element,  # type: ET.Element
            state  # type: _ProcessorState
    ):
        # type: (...) -> Any
        """"""
        parsed_dict = {}

        for child in self._child_processors:
            state.push_location(child.element_path)
            parsed_dict[child.alias] = child.parse_from_parent(element, state)
            state.pop_location()

        return parsed_dict
48144
function parse_html() {
      var reading_js = false, reading_css = false;
      var parser = new htmlparser.Parser({
        onopentag: function(name, attribs){
          if (name === "script" && ! attribs.src && (attribs.type === "text/javascript" || ! attribs.type)){
            reading_js = true;
          }
          else if (name === "style") {
            reading_css = true;
          }
        },
        ontext: function(text){
          if (reading_js) {
            scripts.push(text);
          }
          if (reading_css) {
            styles.push(text);
          }
        },
        onclosetag: function(tagname){
          if (tagname === "script"){
            reading_js = false;
          }
          else if (tagname === "style"){
            reading_css = false;
          }
        }
      });
      parser.write(src);
      parser.end();

      return true;
    }
203271
def parsed(self):
        
        return BeautifulSoup(
            self.response.content,
            features=self.browser.parser,
        )
890213
def parse(html_string, wrapper=Parser, *args, **kwargs):
    
    return Parser(lxml.html.fromstring(html_string), *args, **kwargs)
1085609
function getType(node) {
    const tagLoaders = {
        script: 'javascript',
        style: 'text/css'
    };

    return get(node, 'attrs.type', tagLoaders[node.tag]);
}
844449
def parse_pseudo_class(self, sel, m, has_selector, iselector, is_html):
        """"""

        complex_pseudo = False
        pseudo = util.lower(css_unescape(m.group('name')))
        if m.group('open'):
            complex_pseudo = True
        if complex_pseudo and pseudo in PSEUDO_COMPLEX:
            has_selector = self.parse_pseudo_open(sel, pseudo, has_selector, iselector, m.end(0))
        elif not complex_pseudo and pseudo in PSEUDO_SIMPLE:
            if pseudo == ':root':
                sel.flags |= ct.SEL_ROOT
            elif pseudo == ':defined':
                sel.flags |= ct.SEL_DEFINED
                is_html = True
            elif pseudo == ':scope':
                sel.flags |= ct.SEL_SCOPE
            elif pseudo == ':empty':
                sel.flags |= ct.SEL_EMPTY
            elif pseudo in (':link', ':any-link'):
                sel.selectors.append(CSS_LINK)
            elif pseudo == ':checked':
                sel.selectors.append(CSS_CHECKED)
            elif pseudo == ':default':
                sel.selectors.append(CSS_DEFAULT)
            elif pseudo == ':indeterminate':
                sel.selectors.append(CSS_INDETERMINATE)
            elif pseudo == ":disabled":
                sel.selectors.append(CSS_DISABLED)
            elif pseudo == ":enabled":
                sel.selectors.append(CSS_ENABLED)
            elif pseudo == ":required":
                sel.selectors.append(CSS_REQUIRED)
            elif pseudo == ":optional":
                sel.selectors.append(CSS_OPTIONAL)
            elif pseudo == ":read-only":
                sel.selectors.append(CSS_READ_ONLY)
            elif pseudo == ":read-write":
                sel.selectors.append(CSS_READ_WRITE)
            elif pseudo == ":in-range":
                sel.selectors.append(CSS_IN_RANGE)
            elif pseudo == ":out-of-range":
                sel.selectors.append(CSS_OUT_OF_RANGE)
            elif pseudo == ":placeholder-shown":
                sel.selectors.append(CSS_PLACEHOLDER_SHOWN)
            elif pseudo == ':first-child':
                sel.nth.append(ct.SelectorNth(1, False, 0, False, False, ct.SelectorList()))
            elif pseudo == ':last-child':
                sel.nth.append(ct.SelectorNth(1, False, 0, False, True, ct.SelectorList()))
            elif pseudo == ':first-of-type':
                sel.nth.append(ct.SelectorNth(1, False, 0, True, False, ct.SelectorList()))
            elif pseudo == ':last-of-type':
                sel.nth.append(ct.SelectorNth(1, False, 0, True, True, ct.SelectorList()))
            elif pseudo == ':only-child':
                sel.nth.extend(
                    [
                        ct.SelectorNth(1, False, 0, False, False, ct.SelectorList()),
                        ct.SelectorNth(1, False, 0, False, True, ct.SelectorList())
                    ]
                )
            elif pseudo == ':only-of-type':
                sel.nth.extend(
                    [
                        ct.SelectorNth(1, False, 0, True, False, ct.SelectorList()),
                        ct.SelectorNth(1, False, 0, True, True, ct.SelectorList())
                    ]
                )
            has_selector = True
        elif complex_pseudo and pseudo in PSEUDO_COMPLEX_NO_MATCH:
            self.parse_selectors(iselector, m.end(0), FLG_PSEUDO | FLG_OPEN)
            sel.no_match = True
            has_selector = True
        elif not complex_pseudo and pseudo in PSEUDO_SIMPLE_NO_MATCH:
            sel.no_match = True
            has_selector = True
        elif pseudo in PSEUDO_SUPPORTED:
            raise SelectorSyntaxError(
                "Invalid syntax for pseudo class '{}'".format(pseudo),
                self.pattern,
                m.start(0)
            )
        else:
            raise NotImplementedError(
                "'{}' pseudo-class is not implemented at this time".format(pseudo)
            )

        return has_selector, is_html
134597
def _parse(self, html):
        """"""
        if self._has_body_re.search(html):
            tree = lxml.html.document_fromstring(html).find('.//body')
            self.has_body = True
        else:
            tree = lxml.html.fragment_fromstring(html,
                                                 create_parent=self._root_tag)

        if tree.tag != self._root_tag:
            # ensure the root element exists even if not really needed,
            # so the tree has always the same structure
            root = lxml.html.HtmlElement()
            root.tag = self._root_tag
            root.append(tree)
            return root
        return tree
949062
function extractTypes (elements, Types) {
  function inner (elements, res) {
    const l = elements.length
    for (let i = 0; i < l; i++) {
      const e = elements[i]
      const index = Types.indexOf(e.constructor)
      if (index > -1) {
        res[index].push(e)
      } else if (e instanceof Element) {
        inner(e.content, res)
        inner(e.endContent, res)
      }
    }
  }

  const res = Types.map(() => [])
  inner(elements, res)
  return res
}
1183933
def parse(node, type)
      @type = type
      node.attribute('style').value.to_s.split(';').each do |property|
        if property.include?('margin-top')
          @properties.margins.top = property.split(':').last
        elsif property.include?('margin-left')
          @properties.margins.left = property.split(':').last
        elsif property.include?('margin-right')
          @properties.margins.right = property.split(':').last
        elsif property.include?('width')
          @properties.size.width = property.split(':').last
        elsif property.include?('height')
          @properties.size.height = property.split(':').last
        elsif property.include?('z-index')
          @properties.z_index = property.split(':').last
        elsif property.include?('position')
          @properties.position = property.split(':').last
        end
      end
      @properties.fill_color = Color.new(parent: self).parse_hex_string(node.attribute('fillcolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('fillcolor').nil?
      @properties.stroke.weight = node.attribute('strokeweight').value unless node.attribute('strokeweight').nil?
      @properties.stroke.color = Color.new(parent: self).parse_hex_string(node.attribute('strokecolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('strokecolor').nil?
      @elements = TextBox.parse_list(node.xpath('v:textbox').first, parent: self) unless node.xpath('v:textbox').first.nil?
      self
    end
1240014
def parse(source, **kwargs):
    # type: (Union[Source, str], **Any) -> Document
    """"""
    options = {"no_location": False, "no_source": False}
    options.update(kwargs)

    if isinstance(source, string_types):
        source_obj = Source(source)  # type: Source
    else:
        source_obj = source  # type: ignore

    parser = Parser(source_obj, options)
    return parse_document(parser)
859514
public Object parseValueElement(Element ele, String defaultTypeName) {
    // It's a literal value.
    String value = DomUtils.getTextValue(ele);
    String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE);
    String typeName = specifiedTypeName;
    if (!StringUtils.hasText(typeName)) typeName = defaultTypeName;
    try {
      TypedStringValue typedValue = buildTypedStringValue(value, typeName);
      typedValue.setSource(extractSource(ele));
      typedValue.setSpecifiedTypeName(specifiedTypeName);
      return typedValue;
    } catch (ClassNotFoundException ex) {
      error("Type class [" + typeName + "] not found for <value> element", ele, ex);
      return value;
    }
  }
475563
def _parse_attribute(
            self,
            element,  # type: ET.Element
            attribute,  # type: Text
            state  # type: _ProcessorState
    ):
        # type: (...) -> Any
        """"""
        parsed_value = self._default
        attribute_value = element.get(attribute, None)

        if attribute_value is not None:
            parsed_value = self._parser_func(attribute_value, state)
        elif self.required:
            state.raise_error(
                MissingValue, 'Missing required attribute "{}" on element "{}"'.format(
                    self._attribute, element.tag
                )
            )

        return parsed_value
21408
function(type, text) {
            var parser = parsers.get(type);

            return parser.parsePage(text)
                .get('content');
        }
922232
def parse_html(self, text):
        
        bs = BeautifulSoup(text, "html5lib")
        file_reg = re.compile(MARKDOWN_IMAGE_REGEX, flags=re.IGNORECASE)
        tags = bs.findAll('img')

        for tag in tags:
            # Look for src attribute, remove formatting if added to image
            src_text = tag.get("src") or ""
            formatted_src_match = file_reg.search(src_text)
            src_text = formatted_src_match.group(2) if formatted_src_match else src_text

            alt_text = tag.get("alt") or ""
            tag.replaceWith("![{alt}]({src})".format(alt=alt_text, src=src_text))
        return html.unescape(bs.find('body').renderContents().decode('utf-8'))