Apply ``Cleaner`` to markup string or document and return a cleaned string or document.
776921
def clean_markup(self, markup, parser=None):
        """"""
        result_type = type(markup)
        if isinstance(markup, six.string_types):
            doc = fromstring(markup, parser=parser)
        else:
            doc = copy.deepcopy(markup)
        self(doc)
        if issubclass(result_type, six.binary_type):
            return tostring(doc, encoding='utf-8')
        elif issubclass(result_type, six.text_type):
            return tostring(doc, encoding='unicode')
        else:
            return doc
1290111
def clean(ctx, docs=False, bytecode=False, extra=''):
    ''''''
    patterns = ['build', 'dist', 'cover', 'docs/_build', '**/*.pyc', '*.egg-info', '.tox']
    for pattern in patterns:
        print('Removing {0}'.format(pattern))
        with ctx.cd(ROOT):
            ctx.run('rm -rf {0}'.format(pattern))
355856
def clean_text(text):
    """"""
    new_text = re.sub(ur'\p{P}+', ' ', text)

    new_text = [stem(i) for i in new_text.lower().split() if not
                re.findall(r'[0-9]', i)]

    new_text = ' '.join(new_text)

    return new_text
738747
def text_cleanup(data, key, last_type):
    
    if key in data and last_type == STRING_TYPE:
        data[key] = data[key].strip()
    return data
993288
def clean(docs=False, bytecode=False, extra=''):
    ''''''
    patterns = ['build', 'dist', 'cover', 'docs/_build', '**/*.pyc', '*.egg-info', '.tox', '**/__pycache__']
    for pattern in patterns:
        print('Removing {0}'.format(pattern))
        lrun('rm -rf {0}'.format(pattern))
235162
public static String clean(EvaluationContext ctx, Object text) {
        return Conversions.toString(text, ctx).replaceAll("\\p{C}", "");
    }
1087202
def clean(self):
        """"""
        return Text(self.__text_cleaner.clean(self[TEXT]), **self.__kwargs)
316087
def clean_markdown(text):
    
    result = text

    if isinstance(text, str):
        result = ''.join(
            BeautifulSoup(markdown(text), 'lxml').findAll(text=True))

    return result
687089
def maybe_render_markdown(string: str) -> Any:
    """"""
    if is_ipython_interpreter():  # pragma: no cover
        from IPython.display import Markdown  # type: ignore # noqa: E501

        return Markdown(string)
    else:
        return string
729904
def scrub(data):
    """"""
    # blanks, Nones, and empty strings can stay as is
    if not data:
        return data
    if isinstance(data, (int, float)):
        return data
    if isinstance(data, list):
        return [scrub(entry) for entry in data]
    if isinstance(data, dict):
        return {scrub(key): scrub(value) for key, value in data.items()}
    try:
        return json.encoder.encode_basestring(data)[1:-1]
    except TypeError as exc:
        raise ValidationError("Input '%s' is not a permitted type: %s" % (data,
                                                                          exc))
    except Exception as exc:
        raise ValidationError("Input '%s' not permitted: %s" % (data, exc))
1119535
def tidyHTML(dirtyHTML):
    
    try:
        from tidylib import tidy_document
    except ImportError as e:
        raise ImportError(("%s\nYou need to install pytidylib.\n" +
             "e.g. sudo pip install pytidylib") % e)
    options = {
        'output-xhtml':1,
        #add_xml_decl=1,#option in tidy but not pytidylib
        'indent':1,
        'tidy-mark':1,
        #'char-encoding':'utf8',
        'char-encoding':'raw',
    }
    html, errors = tidy_document(dirtyHTML, options=options)
    return html
766508
def docstring_to_markdown(docstring):
    
    new_docstring_lst = []

    for idx, line in enumerate(docstring.split('\n')):
        line = line.strip()
        if set(line) in ({'-'}, {'='}):
            new_docstring_lst[idx-1] = '**%s**' % new_docstring_lst[idx-1]
        elif line.startswith('>>>'):
            line = '    %s' % line
        new_docstring_lst.append(line)

    for idx, line in enumerate(new_docstring_lst[1:]):
        if line:
            if line.startswith('Description : '):
                new_docstring_lst[idx+1] = (new_docstring_lst[idx+1]
                                            .replace('Description : ', ''))
            elif ' : ' in line:
                line = line.replace(' : ', '` : ')
                new_docstring_lst[idx+1] = '\n- `%s\n' % line
            elif '**' in new_docstring_lst[idx-1] and '**' not in line:
                new_docstring_lst[idx+1] = '\n%s' % line.lstrip()
            elif '**' not in line:
                new_docstring_lst[idx+1] = '    %s' % line.lstrip()

    clean_lst = []
    for line in new_docstring_lst:
        if set(line.strip()) not in ({'-'}, {'='}):
            clean_lst.append(line)
    return clean_lst
466337
def clean_text(text):
    """"""
    # Replace a few nasty unicode characters with their ASCII equivalent
    maps = {u'×': u'x', u'–': u'-', u'−': '-'}
    for element in maps:
        text = text.replace(element, maps[element])

    # Replace genitives
    text = re.sub(r'(?<=\w)\'s\b|(?<=\w)s\'(?!\w)', '  ', text)

    logging.debug(u'Clean text: "%s"', text)

    return text
526638
def clean_document(node):
    """"""
    if node is None or len(node) == 0:
        return None

    logger.debug("\n\n-------------- CLEANING DOCUMENT -----------------")
    to_drop = []

    for n in node.iter():
        # clean out any in-line style properties
        if "style" in n.attrib:
            n.set("style", "")

        # remove embended objects unless it's wanted video
        if n.tag in ("object", "embed") and not ok_embedded_video(n):
            logger.debug("Dropping node %s %r", n.tag, n.attrib)
            to_drop.append(n)

        # clean headings with bad css or high link density
        if n.tag in ("h1", "h2", "h3", "h4") and get_class_weight(n) < 0:
            logger.debug("Dropping <%s>, it's insignificant", n.tag)
            to_drop.append(n)

        if n.tag in ("h3", "h4") and get_link_density(n) > 0.33:
            logger.debug("Dropping <%s>, it's insignificant", n.tag)
            to_drop.append(n)

        # drop block element without content and children
        if n.tag in ("div", "p"):
            text_content = shrink_text(n.text_content())
            if len(text_content) < 5 and not n.getchildren():
                logger.debug(
                    "Dropping %s %r without content.", n.tag, n.attrib)
                to_drop.append(n)

        # finally try out the conditional cleaning of the target node
        if clean_conditionally(n):
            to_drop.append(n)

    drop_nodes_with_parents(to_drop)

    return node
1153123
function getCover(document) {
  var content = markupFiles.getCover();
  return replacements(document, replacements(document, content));
}
1224535
def cleanup_strings(strings, strip: true)
      strings = Array(strings).flatten.map! { |s| cleanup_string(s, strip: strip) }
      strings.reject!(&:blank?)
      strings
    end
198307
def apply_markup(value, arg=None):
    
    if arg is not None:
        return formatter(value, filter_name=arg)
    return formatter(value)