Пример #1
0
 def markdown2html(self, context, source):
     """Markdown to HTML filter respecting the anchor_link_text setting"""
     cell = context.get('cell', {})
     attachments = cell.get('attachments', {})
     renderer = IPythonRenderer(escape=False, attachments=attachments,
                                anchor_link_text=self.anchor_link_text)
     return MarkdownWithMath(renderer=renderer).render(source)
Пример #2
0
def extract_features(text):
    """Extract Markdown Features from text"""
    language = 'undetected'
    try:
        language = LANG_MAP[detect(text)]
        stopwords_set = stopwords.words(language)
        using_stopwords = True
    except Exception:
        stopwords_set = set()
        using_stopwords = False

    renderer = CountRenderer(language, stopwords_set, using_stopwords)
    markdown = MarkdownWithMath(renderer=renderer, escape=False)
    markdown(text)
    renderer.counter['len'] = len(text)
    renderer.counter['lines'] = len(text.split('\n'))
    words = text.split()
    renderer.counter['words'] = len(words)
    renderer.counter['stopwords'] = sum(1 for word in words if word in stopwords_set)

    renderer.counter['meaningful_lines'] = sum(
        value for key, value in renderer.counter.items()
        if key.endswith('_lines')
    )
    #renderer.counter['language'] = detect(text)
    return renderer.counter
Пример #3
0
 def markdown2html(self, context, source):
     cell = context['cell']
     attachments = cell.get('attachments', {})
     renderer = VoilaMarkdownRenderer(escape=False, attachments=attachments,
                                      contents_manager=self.contents_manager,
                                      anchor_link_text=self.anchor_link_text)
     return MarkdownWithMath(renderer=renderer).render(source)
Пример #4
0
 def markdown2html(self, source):
     """Override the base class implementation to force empty tags to be
     XHTML compliant for compatibility with Confluence storage format.
     """
     renderer = IPythonRenderer(escape=False,
                                use_xhtml=True,
                                anchor_link_text=self.anchor_link_text)
     return MarkdownWithMath(renderer=renderer).render(source)
Пример #5
0
def custom_markdown2html(source):
    """
    This filter uses a Custom Rendered that uses a custom CodeHtmlFormatter
    to wrap the language blocks into a <div> and a <pre> tags.
    This is done so it's the same HTML structure that for regular non-language
    sections.
    """
    return MarkdownWithMath(renderer=CustomMarkdownRendered(
        escape=False)).render(source)
Пример #6
0
    def markdown2html(self, context, source):
        """Markdown to HTML filter respecting the anchor_link_text setting"""
        cell = context.get("cell", {})
        attachments = cell.get("attachments", {})
        path = context.get("resources", {}).get("metadata", {}).get("path", "")

        renderer = IPythonRenderer(
            escape=False,
            attachments=attachments,
            embed_images=self.embed_images,
            path=path,
            anchor_link_text=self.anchor_link_text,
            exclude_anchor_links=self.exclude_anchor_links,
        )
        return MarkdownWithMath(renderer=renderer).render(source)
Пример #7
0
    def _items_from_notebook(self):
        """Yield LinkItems from a notebook"""
        import nbformat
        from nbconvert.filters.markdown_mistune import IPythonRenderer, MarkdownWithMath

        nb = nbformat.read(str(self.fspath), as_version=4)
        for cell_num, cell in enumerate(nb.cells):
            if cell.cell_type != 'markdown':
                continue

            attachments = cell.get('attachments', {})
            renderer = IPythonRenderer(escape=False, attachments=attachments)
            html = MarkdownWithMath(renderer=renderer).render(cell.source)
            basename = 'Cell %i' % cell_num
            for item in links_in_html(basename, self, html):
                ignore = False
                for pattern in self.ignore_links:
                    if re.match(pattern, item.target):
                        ignore = True
                if not ignore:
                    yield item
Пример #8
0
 def markdown2html(self, source):
     """Markdown to HTML filter respecting the anchor_link_text setting"""
     renderer = IPythonRenderer(escape=False,
                                anchor_link_text=self.anchor_link_text)
     return MarkdownWithMath(renderer=renderer).render(source)
Пример #9
0
def markdown2html_custom(source):
    """Convert a markdown string to HTML using mistune"""
    return MarkdownWithMath(renderer=MyMarkdownRenderer(
        escape=False)).render(source)
Пример #10
0
 def markdown2html(self, source):
     renderer = FletteIPythonRenderer(
         escape=False, anchor_link_text=self.anchor_link_text)
     return MarkdownWithMath(renderer=renderer).render(source)
Пример #11
0
def md_to_flowables(src, stylesheet):
    inliner_lexer = mistune.InlineLexer(InlineRenderer())
    converter = MarkdownWithMath(renderer=BlockRenderer(stylesheet=stylesheet),
                                 inline=inliner_lexer)
    return converter.render(src)
Пример #12
0
def custom_markdown2html(source):
    return MarkdownWithMath(renderer=CustomMarkdownRendered(
        escape=False)).render(source)
Пример #13
0
def scan_markdown(source):
    renderer = MathRecordingRenderer()
    MarkdownWithMath(renderer=renderer).render(source)
    return renderer.extracted_math