Wrap text with markdown specific flavour.
552259
def build_code(self, lang, body):
        """"""
        self.out.append("```" + lang)
        self.build_markdown(lang, body)
        self.out.append("```")
1037729
def optwrap(self, text):
        """"""
        if not self.body_width:
            return text

        assert wrap, "Requires Python 2.3."
        result = ''
        newlines = 0
        for para in text.split("\n"):
            if len(para) > 0:
                if not skipwrap(para):
                    result += "\n".join(wrap(para, self.body_width))
                    if para.endswith('  '):
                        result += "  \n"
                        newlines = 1
                    else:
                        result += "\n\n"
                        newlines = 2
                else:
                    if not onlywhite(para):
                        result += para + "\n"
                        newlines = 1
            else:
                if newlines < 2:
                    result += "\n"
                    newlines += 1
        return result
90946
def markdown(text)
      renderer = HTMLwithPygments.new(hard_wrap: true, filter_html: false, with_toc_data: false)
      options = {
        autolink: true,
        no_intra_emphasis: true,
        fenced_code_blocks: true,
        lax_html_blocks: true,
        tables: true,
        strikethrough: true,
        superscript: true,
        xhtml: true
      }
      Redcarpet::Markdown.new(renderer, options).render(text).html_safe
    end
1033510
def markdown_single_text(self, catalog, cdli_number):
        
        if cdli_number in catalog:
            pnum = catalog[cdli_number]['pnum']
            edition = catalog[cdli_number]['edition']
            metadata = '\n\t'.join(catalog[cdli_number]['metadata'])
            transliteration = '\n\t'.join(catalog[cdli_number]['transliteration'])
            normalization = '\n\t'.join(catalog[cdli_number]['normalization'])
            translation = '\n\t'.join(catalog[cdli_number]['translation'])
            m_d = """{edition}
{pnum}
---
### metadata
    {metadata}
### transliteration
    {trans}
### normalization
    {norm}
### translation
    {translation}  
""".format(pnum=pnum, edition=edition, metadata=metadata,
           trans=transliteration, norm=normalization,
           translation=translation)
            self.markdown_text = m_d
641230
def render_text(text, language=None):
    
    # Get the filter
    text_filter = SUPPORTED_LANGUAGES.get(language, None)
    if not text_filter:
        raise ImproperlyConfigured("markup filter does not exist: {0}. Valid options are: {1}".format(
            language, ', '.join(list(SUPPORTED_LANGUAGES.keys()))
        ))

    # Convert.
    return text_filter(text)
759970
def MarkDown(node):
    
    cur = node.first_child

    # Go into each child, in turn
    output = []
    while cur is not None:
        t = cur.t
        if t == 'paragraph':
            output.append(paragraph(cur))
        elif t == 'text':
            output.append(text(cur))
        elif t == 'softbreak':
            output.append(softbreak(cur))
        elif t == 'linebreak':
            output.append(hardbreak(cur))
        elif t == 'link':
            output.append(reference(cur))
        elif t == 'heading':
            output.append(title(cur))
        elif t == 'emph':
            output.append(emphasis(cur))
        elif t == 'strong':
            output.append(strong(cur))
        elif t == 'code':
            output.append(literal(cur))
        elif t == 'code_block':
            output.append(literal_block(cur))
        elif t == 'html_inline' or t == 'html_block':
            output.append(raw(cur))
        elif t == 'block_quote':
            output.append(block_quote(cur))
        elif t == 'thematic_break':
            output.append(transition(cur))
        elif t == 'image':
            output.append(image(cur))
        elif t == 'list':
            output.append(listNode(cur))
        elif t == 'item':
            output.append(listItem(cur))
        elif t == 'MDsection':
            output.append(section(cur))
        else:
            print('Received unhandled type: {}. Full print of node:'.format(t))
            cur.pretty()

        cur = cur.nxt

    return output
642692
def _filter(self, text):
        """"""

        self.markdown.reset()
        return self.markdown.convert(text)
374794
def patch_text(actions, tree):
    """"""
    tree = etree.fromstring(tree)
    actions = patch.DiffParser().parse(actions)
    tree = patch_tree(actions, tree)
    return etree.tounicode(tree)
1139225
def wrap_str_of(self, text):
        """"""
        text_repr = ascii(text)
        internal_assert(text_repr[0] == text_repr[-1] and text_repr[0] in ("'", '"'), "cannot wrap str of", text)
        return self.wrap_str(text_repr[1:-1], text_repr[-1])
1306988
def markup_description(description):
    
    if apply_markdown:
        description = apply_markdown(description)
    else:
        description = escape(description).replace('\n', '<br />')
        description = '<p>' + description + '</p>'
    return mark_safe(description)
570895
def _htmlify_text(self, s):
    """"""
    colored = self._handle_ansi_color_codes(html.escape(s))
    return linkify(self._buildroot, colored, self._linkify_memo).replace('\n', '</br>')
1217074
def wrap(self, text, width=None, indent=None):
        
        width = width if width is not None else self.options.wrap_length
        indent = indent if indent is not None else self.indentation
        initial_indent = self.initial_indentation
        return textwrap.fill(text, width=width,
                             initial_indent=initial_indent,
                             subsequent_indent=indent)
455570
def pixlen(text, widthlist, fontsize):
    """"""
    pl = 0.0
    for t in text:
        pl += widthlist[ord(t)]
    return pl * fontsize
915416
def text_width(text):
    """"""
    (xmin, xmax, d1, d2) = get_dimension(text)
    return xmax - xmin
1231568
def _get_markup(self, text, is_markdown, **kwargs):
        
        if is_markdown:
            return markdown.to_html(
                text,
                config=kwargs,
                search_path=self.search_path)

        return html_entry.process(
            text,
            config=kwargs,
            search_path=self.search_path)
44517
def text_width(string, font_name, font_size):
    """"""
    return stringWidth(string, fontName=font_name, fontSize=font_size)
251986
def concat(self, formatted_text):
        """"""
        assert self._is_compatible(formatted_text), "Cannot concat text with different modes"
        self.text += formatted_text.text
        return self