Grabs the text from an element and preserves whitespace
163965
function _getText(el) {
    var theText;
    // Make sure to check for type of string because if the body of the page
    // doesn't have any text it'll be "" which is falsey and will go into
    // the else which is meant for Firefox and shit will break
    if (typeof document.body.innerText == 'string') {
      theText = el.innerText;
    }
    else {
      // First replace <br>s before replacing the rest of the HTML
      theText = el.innerHTML.replace(/<br>/gi, "\n");
      // Now we can clean the HTML
      theText = theText.replace(/<(?:.|\n)*?>/gm, '');
      // Now fix HTML entities
      theText = theText.replace(/&lt;/gi, '<');
      theText = theText.replace(/&gt;/gi, '>');
    }
    return theText;
  }
1181300
def get_whitespace(txt):
    

    # if the entire parameter is whitespace
    rall = re.search(r'^([\s])+$', txt)
    if rall:
        tmp = txt.split('\n', 1)
        if len(tmp) == 2:
            return (tmp[0], '\n' + tmp[1])  # left, right
        else:
            return ('', tmp[0])  # left, right
    left = ''
    # find whitespace to the left of the parameter
    rlm = re.search(r'^([\s])+', txt)
    if rlm:
        left = rlm.group(0)
    right = ''
    # find whitespace to the right of the parameter
    rrm = re.search(r'([\s])+$', txt)
    if rrm:
        right = rrm.group(0)
    return (left, right)
1123748
def get_element(self, line, column):
        """"""
        ichar = self.charindex(line, column)
        icontains = self.contains_index
        result = None

        if line < icontains:
            #We only need to search through the types and members.
            maxstart = 0
            tempresult = None
            for t in self.types:
                if ichar >= self.types[t].absstart:
                    if self.types[t].absstart > maxstart:
                        maxstart = self.types[t].absstart
                        tempresult = self.types[t]

            #This takes the possibility of an incomplete type into account
            if (tempresult is not None and (ichar <= tempresult.end or 
                                            tempresult.incomplete)):
                result = tempresult

            if not result:
                #Members only span a single line usually and don't get added
                #without an end token.
                for m in self.members:
                    if (ichar >= self.members[m].start and 
                        ichar <= self.members[m].end):
                        result = self.members[m]
                        break
        else:
            #We only need to search through the executables
            tempresult = None
            maxstart = 0
            for iexec in self.executables:
                if (ichar >= self.executables[iexec].absstart):
                    if self.executables[iexec].absstart > maxstart:
                        maxstart = self.executables[iexec].absstart
                        tempresult = self.executables[iexec]

            if tempresult is not None and (ichar <= tempresult.end or
                                           tempresult.incomplete):
                result = tempresult

        if result is None:
            #We must be in the text of the module, return the module
            return self
        else:
            return result
17127
private static String getText(Element element) {
    if (element.getFirstChild() == null) {
      return "";
    }
    return ((Text) element.getFirstChild()).getData().trim();
  }
666359
function processHTML() {
            /**
             * Genetrate an iterator of the index where non whitespace appear
             * @param {string} text The text to set
             * @returns {number} The index
             */
            function* genWordStartIndices(text) {
                if (!text.trim()) {
                    return
                }
                const re = /\s/u
                let preIsWhitespace = true
                let i = 0
                for (const c of text) {
                    const isWhitespace = re.test(c)
                    if (preIsWhitespace && !isWhitespace) {
                        yield i
                    }
                    preIsWhitespace = isWhitespace
                    i++
                }
            }

            /**
             * Check whether the given token is a dummy element.
             * @param {Token} node The token to check.
             * @returns {boolean} `true` if the token is a dummy element.
             */
            function isDummyElement(node) {
                return (
                    !node.startTag &&
                    (node.name === "body" ||
                        node.name === "head" ||
                        node.name === "html")
                )
            }

            /**
             * Get the start token of Element
             * @param  {Node} elementNode The element node
             * @returns {Token} The start token
             */
            function getStartToken(elementNode) {
                if (!elementNode) {
                    return null
                }
                if (elementNode.type !== "HTMLElement") {
                    return null
                }
                if (isDummyElement(elementNode)) {
                    return null
                }
                return elementNode.startTag || elementNode
            }

            microTemplateService.traverseDocumentNodes({
                HTMLElement(node) {
                    if (isDummyElement(node)) {
                        return
                    }
                    const elementNode =
                        microTemplateService.getBranchProcessedHtmlNode(
                            node,
                            sourceCode
                        ) || node
                    const startToken = getStartToken(elementNode)
                    const parentStartToken = getStartToken(elementNode.parent)
                    if (parentStartToken) {
                        // self indent
                        setOffsetToToken(
                            startToken,
                            1,
                            parentStartToken.loc.start.line
                        )
                    } else {
                        setOffsetRootToIndex(startToken.range[0])
                    }
                    if (
                        IGNORE_INDENT_ELEMENT_NAMES.find(
                            name => name === elementNode.name
                        )
                    ) {
                        ignoreRanges.push([
                            elementNode.startTag
                                ? elementNode.startTag.range[1]
                                : elementNode.range[0],
                            elementNode.endTag
                                ? elementNode.endTag.range[0]
                                : elementNode.range[1],
                        ])
                    }
                },
                HTMLStartTag(node) {
                    const attrs = node.attributes.concat(node.ignoredAttributes)
                    setOffsetToToken(
                        attrs,
                        options.attribute,
                        node.loc.start.line
                    )
                    const start = node.tagOpen
                        ? node.tagOpen.range[1]
                        : node.range[0]
                    const end = node.tagClose
                        ? node.tagClose.range[0]
                        : node.range[1]
                    const attrTemplateTokens = microTemplateService
                        .getMicroTemplateTokens()
                        .filter(token => {
                            if (
                                token.range[0] < start ||
                                end < token.range[1]
                            ) {
                                return false
                            }
                            return !attrs.some(
                                n =>
                                    token.range[0] < n.range[1] &&
                                    n.range[0] < token.range[1]
                            )
                        })
                    setOffsetToToken(
                        attrTemplateTokens,
                        options.attribute,
                        node.loc.start.line
                    )

                    if (node.tagClose) {
                        setOffsetToToken(
                            node.tagClose,
                            options.closeBracket,
                            node.loc.start.line
                        )
                    }
                },
                HTMLEndTag(node) {
                    const endTag =
                        microTemplateService.getBranchProcessedHtmlNode(
                            node,
                            sourceCode
                        ) || node
                    const startToken = getStartToken(endTag.parent)
                    if (startToken) {
                        // self indent
                        setOffsetToToken(endTag, 0, startToken.loc.start.line)
                    }

                    if (endTag.tagClose) {
                        setOffsetToToken(
                            endTag.tagClose,
                            options.closeBracket,
                            endTag.loc.start.line
                        )
                    }
                },
                HTMLText(node) {
                    const textNode =
                        microTemplateService.getBranchProcessedHtmlNode(
                            node,
                            sourceCode
                        ) || node

                    const textHTML = sourceCode.text.slice(
                        textNode.range[0],
                        textNode.range[1]
                    )
                    const startToken = getStartToken(textNode.parent)
                    if (startToken) {
                        // self indent
                        for (const i of genWordStartIndices(textHTML)) {
                            setOffsetToIndex(
                                textNode.range[0] + i,
                                1,
                                startToken.loc.start.line
                            )
                        }
                    } else {
                        for (const i of genWordStartIndices(textHTML)) {
                            setOffsetRootToIndex(textNode.range[0] + i)
                        }
                    }
                },
                HTMLComment(node) {
                    const commentNode =
                        microTemplateService.getBranchProcessedHtmlNode(
                            node,
                            sourceCode
                        ) || node
                    const startToken = getStartToken(commentNode.parent)
                    if (startToken) {
                        // self indent
                        setOffsetToToken(
                            commentNode,
                            1,
                            startToken.loc.start.line
                        )
                    } else {
                        setOffsetRootToIndex(commentNode.range[0])
                    }

                    const commentStart = commentNode.range[0] + 4
                    const commentEnd = commentNode.range[1] - 3
                    const comment = sourceCode.text.slice(
                        commentStart,
                        commentEnd
                    )

                    for (const i of genWordStartIndices(comment)) {
                        setOffsetToIndex(
                            commentStart + i,
                            1,
                            commentNode.loc.start.line
                        )
                    }
                    setOffsetToIndex(commentEnd, 0, commentNode.loc.start.line)
                },
            })
        }
264797
function skipWhitespace() {
    while (i < input.length) {
      if (isWhitespace(input[i])) {
        i++;
        parser.pos_++;
        continue;
      }
      break;
    }
  }
971957
def string(
        element_name,  # type: Text
        attribute=None,  # type: Optional[Text]
        required=True,  # type: bool
        alias=None,  # type: Optional[Text]
        default='',  # type: Optional[Text]
        omit_empty=False,  # type: bool
        strip_whitespace=True,  # type: bool
        hooks=None  # type: Optional[Hooks]
):
    # type: (...) -> Processor
    
    value_parser = _string_parser(strip_whitespace)
    return _PrimitiveValue(
        element_name,
        value_parser,
        attribute,
        required,
        alias,
        default,
        omit_empty,
        hooks
    )
168907
def text(self, clean=True):
        
        if clean:
            return utils.normalise_whitespace(''.join(self).replace('\n', ' '))
        else:
            return ''.join(self)
1261031
private void skipWhitespace()
    {
        while (ivPos < ivString.length() && Character.isWhitespace(ivString.charAt(ivPos)))
        {
            ivPos++;
        }
    }
302502
def get_text_from_node(self, node, regex=None, group=1):
        """"""
        text = self._get_stripped_text_from_node(node)

        if regex is not None:
            text = self._filter_by_regex(regex, text, group)

        return text
790203
function trimWhitespace(line) {
  let whitespaceIndicies = [];
  let allWhitespace = true;
  let seenAnyTag = false;
  let newLine = new Array(line.length);
  for (let i = 0; i < line.length; i++) {
    let obj = line[i];
    newLine[i] = obj;
    if (typeof obj === 'string') {
      if (!nonWhitespace.test(obj)) {
        whitespaceIndicies.push(i);
      } else {
        allWhitespace = false;
      }
    } else {
      seenAnyTag = true;
      if (nonWhitespaceNodes[obj.type] === true) {
        allWhitespace = false;
      }
    }
    // Bail out if we've seen a non-whitespace
    if (!allWhitespace) {
      return line;
    }
  }

  // Remove the whitespace nodes if this line consists of:
  //  - only whitespace text
  //  - no Interpolators or Unescaped Interpolators
  //  - at least one Mustache tag
  if (allWhitespace && seenAnyTag) {
    for (let i = 0; i < whitespaceIndicies.length; i++) {
      let index = whitespaceIndicies[i];
      let obj = newLine[index];
      newLine[index] = {
        type: types.TEXT,
        original: obj,
        length: obj.length
      };
    }
  }

  return newLine;
}
985469
def collapse_whitespace(message):
    """"""
    return u' '.join(map(lambda s: s.strip(),
                         filter(None, message.strip().splitlines())))
920572
function consumeWhitespace(remaining) {
  var match = remaining.match(/^\s+/);

  if (match) {
    var consumed = match[0];
    remaining = remaining.substring(consumed.length);
  }

  return remaining;
}
1032255
def clean_text(self, text, preserve_space):
        
        if text is None:
            return
        if preserve_space:
            text = text.replace('\r\n', ' ').replace('\n', ' ').replace('\t', ' ')
        else:
            text = text.replace('\r\n', '').replace('\n', '').replace('\t', ' ')
            text = text.strip()
            while ('  ' in text):
                text = text.replace('  ', ' ')
        return text
1191780
static String getElementText(Element element) {
        StringBuffer buf = new StringBuffer();

        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            if (node.getNodeType() == Node.TEXT_NODE ||
                    node.getNodeType() == Node.CDATA_SECTION_NODE) {
                Text text = (Text) node;
                buf.append(text.getData().trim());
            }
        }

        return buf.toString();
    }
626360
def scrub(value, scrub_text=_keep_whitespace, scrub_number=_scrub_number):
    
    return _scrub(value, set(), [], scrub_text=scrub_text, scrub_number=scrub_number)
418663
function wrapTextAndGetRange(pre, text, post) {
  return {
    result: `${pre}${text}${post}`,
    from: pre.length,
    to: pre.length + text.length
  };
}