Skip to content

cfangmeier/markdown-bokeh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markdown-bokeh

This is an extension to Python-Markdown which provides the ability to include plots from bokeh. This is essentially a modified version of markdown-include that inserts the generated javascript and html into the raw markdown file prior to further processing.

Installation

git clone git@github.com:cfangmeier/markdown-bokeh.git
cd markdown-bokeh
python setup.py install --user

You can also install from pypi via pip

pip install markdown-bokeh

Usage

This module can be used in a program in the following way:

import markdown
html = markdown.markdown(source, extensions=['markdown_bokeh.bokeh'])

Or, if like me, you are generating a site with Pelican,

MARKDOWN = {
    'extension_configs': {
        'markdown_bokeh.bokeh': {},
        'markdown.extensions.codehilite': {'css_class': 'highlight'},
        'markdown.extensions.extra': {},
        'markdown.extensions.meta': {},
    },
    'output_format': 'html5',
}

You need to first save the components of your bokeh figure like

from bokeh.embed import components
script, div = components(fig)

with open(f'{basename}.js', 'w') as f:
    f.write(script)
with open(f'{basename}.html', 'w') as f:
    f.write(div)

The syntax for use within your Markdown files is {!basename!}(caption). This statement will be replaced by the contents of basename.js and basename.html.

By default, all file-names are evaluated relative to the location from which Markdown is being called. If you would like to change the directory relative to which paths are evaluated, then this can be done by specifying the extension setting base_path.

About

Include bokeh generated plots in your markdown.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages