DEPRECATED: return text content with children (#62), sub-elements (#66)

    Only used by deprecated template_to_dict_find(), and suffers from
    copypasta code smell.
550596
def text_with_children(node, debug=0):
    

    # https://stackoverflow.com/questions/4624062/get-all-text-inside-a-tag-in-lxml

    if sys.version.startswith('3'):  # py3 needs encoding=str
        parts = ([node.text] +
                 list(chain(
                     *([tostring(c, with_tail=False, encoding=str),
                        c.tail] for c in node.getchildren())))
                 + [node.tail])
    else:
        parts = ([node.text] +
                 list(chain(
                     *([tostring(c, with_tail=False),
                        c.tail] for c in node.getchildren())))
                 + [node.tail])

    value = ''.join(filter(lambda x: x or isinstance(x, str), parts)).strip()

    if debug > 1:
        print("+ text_with_children:")
        print("  %s" % value)

    return value
106285
def get_text(self):
        """"""
        if self.__fulltext:
            return self.__fulltext
        else:
            self.__fulltext = "\n\n".join(text.get_text()
                                          for text in self.__subtrees)
            return self.__fulltext
76364
def content(self, output=None, str_output=None, **kwargs):
        """"""
        if self.response.mimetype != "text/html":
            raise Failure(_("expected request to return HTML, but it returned {}").format(
                self.response.mimetype))

        # TODO: Remove once beautiful soup updates to accomodate python 3.7
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            content = BeautifulSoup(self.response.data, "html.parser")

        return self._search_page(
            output,
            str_output,
            content,
            lambda regex, content: any(regex.search(str(tag)) for tag in content.find_all(**kwargs)))
1081051
def from_string(cls, contents, **kwargs):
		
		lines = contents.splitlines()
		title = None
		description = None

		line = lines.pop(0)
		while line != '':
			if not title and line.startswith('#'):
				title = line[1:].strip()
			elif line.startswith('title:'):
				title = line[6:].strip()
			elif line.startswith('description:'):
				description = line[12:].strip()
			elif line.startswith('subtitle:'):
				kwargs['subtitle'] = line[9:].strip()
			elif line.startswith('comments:'):
				try:
					kwargs['allow_comments'] = _str_to_bool(line[9:])
				except ValueError:
					LOG.warning('invalid boolean value for comments', exc_info=True)

			cls.process_meta(line, kwargs)

			line = lines.pop(0)

		# the only lines left should be the actual contents
		body = '\n'.join(lines).strip()
		excerpt = _get_excerpt(body)
		if description is None:
			description = _get_description(excerpt, 160)
		if issubclass(cls, Post):
			kwargs['excerpt'] = render_markdown(excerpt)
		body = render_markdown(body)

		return cls(title=title, body=body, description=description, **kwargs)
278234
def sublistReader(xmlelement):
    
    #Note: actually I'm not 100% sure how this function behaves
    elements = list()
    params, children = extractParams(xmlelement)
    for child in children:
        currElement = dict()
        currElement.update(child.attrib)
        childparams, subchildren = extractParams(child)
        if childparams:
            currElement['params'] = childparams
        for subchild in subchildren:
            subchildTag = clearTag(subchild.tag)
            if 'List' in subchildTag:
                listelements, listparams = sublistReader(subchild)
                simplelist = [listelement['params'] for listelement in listelements]
                currElement[subchildTag] = simplelist
            else:
                subchildparams, _ = extractParams(subchild)
                currElement[subchildTag] = subchildparams
                if subchildTag == 'binary' and subchild.text:
                    currElement[subchildTag] = subchild.text.strip()
        elements.append(currElement)
    return elements, params
667227
def get_edu_text(text_subtree):
    """"""
    assert text_subtree.label() == 'text', "text_subtree: {}".format(text_subtree)
    edu_str = u' '.join(word for word in text_subtree.leaves())
    return re.sub('_!(.*?)_!', '\g<1>', edu_str)
254196
def newText(content):
    
    ret = libxml2mod.xmlNewText(content)
    if ret is None:raise treeError('xmlNewText() failed')
    return xmlNode(_obj=ret)
463064
def contents(self):
        

        if self.children is None:
            return self._contents

        if self._is_mutated():
            self._set_contents()

        return self._contents
1181296
function getTextFromContent(contentNodes) {
  if (contentNodes === null) {
    return '';
  }
  const texts = [...contentNodes].map(node => node.textContent);
  const text = texts.join('').trim();
  return unescapeHtml(text);
}
710875
function extractTextContent (node) {
    var buf = []
    var textContent
    
    switch (node.nodeType) {
      case 1: // Element node such as <p> or <div>
      case 11: // A DocumentFragment node ( a minimal document object that has no parent)
        node = node.firstChild
        while (node) {
          // Type 7 = a ProcessingInstruction of an XML document such as <?xml-stylesheet ... ?> declaration
          // Type 8 = a Comment node
          if (node.nodeType !== 7 && node.nodeType !== 8) {
            textContent = extractTextContent(node)
            
            if (textContent.length > 0 && buf.length > 0) {
              var previousTextContent = buf[buf.length - 1]
              
              if (textContent[0] !== ' ' && previousTextContent.length > 0 && previousTextContent[previousTextContent.length - 1] !== ' ') {
                buf.push(' ')
              }
            }
            
            buf.push(textContent)
          }
          node = node.nextSibling
        }
        return buf.join('')
      default:
        return node.nodeValue
    }
  }
232556
def node_contents_str(tag):
    
    if not tag:
        return None
    tag_string = ''
    for child_tag in tag.children:
        if isinstance(child_tag, Comment):
            # BeautifulSoup does not preserve comment tags, add them back
            tag_string += '<!--%s-->' % unicode_value(child_tag)
        else:
            tag_string += unicode_value(child_tag)
    return tag_string if tag_string != '' else None
1131844
def get_text(self, node):
        """"""
        try:
            return node.children[0].content or ""
        except (AttributeError, IndexError):
            return node.content or ""
6861
def fromHTML(html, *args, **kwargs):
        
        source = BeautifulSoup(html, 'html.parser', *args, **kwargs)
        return TOC('[document]',
            source=source,
            descendants=source.children)
1144159
def get_text(html_content, display_images=False, deduplicate_captions=False, display_links=False):
    '''
    
    '''
    html_content = html_content.strip()
    if not html_content:
        return ""

    # strip XML declaration, if necessary
    if html_content.startswith('<?xml '):
        html_content = RE_STRIP_XML_DECLARATION.sub('', html_content, count=1)

    html_tree = fromstring(html_content)
    parser = Inscriptis(html_tree, display_images=display_images, deduplicate_captions=deduplicate_captions, display_links=display_links)
    return parser.get_text()
259464
def getText(node, recursive=False):
    """"""
    L = [u'']
    for n in node.childNodes:
        if n.nodeType in (node.TEXT_NODE, node.CDATA_SECTION_NODE):
            L.append(n.data)
        else:
            if not recursive:
                return None
        L.append(getText(n))
    return u''.join(L)
1225896
def _get_template_dict(template):
    
    if isinstance(template, str):
        return parse_template(template)

    if isinstance(template, dict):
        return copy.deepcopy(template)

    raise ValueError('Input template should be a string or dictionary')
1099403
def elements_as_text(self, elems, indent=2):
        
        assert elems
        text = ""
        for elename, eledesc in elems.items():
            if isinstance(eledesc, dict):
                desc_txt = self.elements_as_text(eledesc, indent + 2)
                desc_txt = ''.join(['\n', desc_txt])
            elif isinstance(eledesc, str):
                desc_txt = ''.join([eledesc, '\n'])
            else:
                assert False, "Only string or dictionary"
            ele_txt = "\t{0}{1: <22} {2}".format(' ' * indent, elename,
                                                 desc_txt)
            text = ''.join([text, ele_txt])
        return text