Beispiel #1
0
def convert_markdown(markdown_source, extensions=()):
    """
    Convert the Markdown source file to HTML content, and additionally
    return the parsed table of contents, and a dictionary of any metadata
    that was specified in the Markdown file.

    `extensions` is an optional sequence of Python Markdown extensions to add
    to the default set.
    """

    # Prepend a table of contents marker for the TOC extension
    markdown_source = toc.pre_process(markdown_source)

    # Generate the HTML from the markdown source
    md = markdown.Markdown(
        extensions=['meta', 'toc', 'tables', 'fenced_code'] + list(extensions)
    )
    html_content = md.convert(markdown_source)
    meta = md.Meta

    # Strip out the generated table of contents
    (html_content, toc_html) = toc.post_process(html_content)

    # Post process the generated table of contents into a data structure
    table_of_contents = toc.TableOfContents(toc_html)

    return (html_content, table_of_contents, meta)
Beispiel #2
0
def convert_markdown(markdown_source, extensions=()):
    """
    Convert the Markdown source file to HTML content, and additionally
    return the parsed table of contents, and a dictionary of any metadata
    that was specified in the Markdown file.

    `extensions` is an optional sequence of Python Markdown extensions to add
    to the default set.
    """

    # Prepend a table of contents marker for the TOC extension
    markdown_source = toc.pre_process(markdown_source)

    # Generate the HTML from the markdown source
    md = markdown.Markdown(
        extensions=['meta', 'toc', 'tables', 'fenced_code'] + list(extensions)
    )
    html_content = md.convert(markdown_source)
    meta = md.Meta

    # Strip out the generated table of contents
    (html_content, toc_html) = toc.post_process(html_content)

    # Post process the generated table of contents into a data structure
    table_of_contents = toc.TableOfContents(toc_html)

    return (html_content, table_of_contents, meta)
Beispiel #3
0
def create_api_content(event):
    """
    Callback for the GenerateContent event.  If the page stored within the event is an ApiPage, it will
    will create HTML content based on the page's object.  Otherwise, it will pass along to the base instruction.

    ### Parameters
        event | <mkdocs.events.BuildPage>

    ### Returns
        <bool> | consumed
    """
    if isinstance(event.page, nav.ApiPage):
        theme = os.path.basename(event.config['theme_dir'][0])
        theme_path = os.path.join(os.path.dirname(__file__), 'themes', theme)
        loader = jinja2.FileSystemLoader(theme_path)
        env = jinja2.Environment(loader=loader)

        template = env.get_template(event.page.template_name)

        html_content = template.render(event.page.render_context)
        html_content, toc_html = toc.post_process(html_content)

        event.html_content = html_content
        event.table_of_contents = toc.TableOfContents(toc_html)
        event.consumed
Beispiel #4
0
def convert_markdown(markdown_source):
    """
    Convert the Markdown source file to HTML content, and additionally
    return the parsed table of contents, and a dictionary of any metadata
    that was specified in the Markdown file.
    """

    # Prepend a table of contents marker for the TOC extension
    markdown_source = toc.pre_process(markdown_source)

    # Generate the HTML from the markdown source
    md = markdown.Markdown(extensions=['meta', 'toc', 'tables', 'fenced_code', 'codehilite(pygments_style=borland)'])
    html_content = md.convert(markdown_source)
    meta = md.Meta

    # Strip out the generated table of contents
    (html_content, toc_html) = toc.post_process(html_content)

    # Post process the generated table of contents into a data structure
    table_of_contents = toc.TableOfContents(toc_html)

    return (html_content, table_of_contents, meta)
Beispiel #5
0
 def markdown_to_toc(self, markdown_source):
     markdown_source = toc.pre_process(markdown_source)
     md = markdown.Markdown(extensions=['toc'])
     html_output = md.convert(markdown_source)
     html_output, toc_output = toc.post_process(html_output)
     return toc.TableOfContents(toc_output)
Beispiel #6
0
 def markdown_to_toc(self, markdown_source):
     markdown_source = toc.pre_process(markdown_source)
     md = markdown.Markdown(extensions=['toc'])
     html_output = md.convert(markdown_source)
     html_output, toc_output = toc.post_process(html_output)
     return toc.TableOfContents(toc_output)