Skip to content

Bradfield/gitbook-plugin-literate-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gitbook plugin for literate Python

A quick and dirty plugin for writing executable Python files that can also render to html, ebook etc by way of gitbook.

To use, add the "# -- litpy --" pragma to your markdown file, then write it as if it were an ordinary Python module. The plugin will convert all module-level docstrings to text and wrap Python in Python code blocks, so:

# -*- litpy -*-
"""
This will be parsed as *markdown* by gitbook
"""
def this_function_will_be_wrapped():
    # in ```python code blocks

... will be converted to:

<p>
  This will be parsed as *markdown* by gitbook
</p>
<pre><code>
def this_function_will_be_wrapped():
    # in ```python code blocks
</code></pre>

Since the file has a non-".py" extension, you will need to use the imp module to import it elsewhere, for instance for testing purposes:

import imp
import os

dirname = os.path.dirname(os.path.realpath(__file__))
source_file = os.path.join(dirname, 'knights-tour.md')
knights_tour = imp.load_source('knights_tour', source_file)

See this gitbook page and corresponding test for a full example.

About

Quick and dirty literate Python plugin for GitBook

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published