Skip to main content

Inrterface wrapper for Stitch/Knotr: reproducible report generation tool via Jupyter, Pandoc and Markdown. Export to Jupyter notebook via Notedown.

Project description

Build Status

Knitty is a Pandoc filter and Atom/Hydrogen friendly inrterface wrapper for Stitch/Knotr: reproducible report generation tool via Jupyter, Pandoc and Markdown. Insert python code (or other Jupyter kernel code) to the Markdown document and have code’s results in the output document. Exports to Jupyter notebook via Notedown.

See Knitty documentation.

You can use vscode-ipynb-py-converter to convert .ipynb to .py to use with Knitty.

Install

Install as part of Pandoctools - convenient interface and works out of the box.

Needs Python 3.6+ but you can have other versions via Jupyter kernels as Knitty can use any installed kernel.

Or install on Windows (if you use conda package manager (Anaconda/Miniconda) then you can install dependencies first):

conda install -c defaults -c conda-forge "pip>=10.0.1" "pandoc>=2.2.1" jupyter_core ^
traitlets ipython jupyter_client nbconvert pandocfilters pypandoc click psutil nbformat ^
pandoc-attributes pyyaml
pip install knitty

If pip install fails try to change codepage: chcp 1252.

On Unix:

conda install -c defaults -c conda-forge "pip>=10.0.1" "pandoc>=2.2.1" jupyter_core \
traitlets ipython jupyter_client nbconvert pandocfilters pypandoc click psutil nbformat \
pandoc-attributes pyyaml
pip install knitty

Pandoc ≥ 2.0 is needed for proper Knitty output re-processing. In particular for nested HTML insertions to Markdown for toolchain: file.mdfile.md.mdfile.md.md.html. Pandoc 2.1.* does not works on windows.

Optional install

If you would like to use knotedown to import from R Markdown you need installed knitr:

conda install r-knitr r-reticulate

Usage

Unix:

export PYTHONIOENCODING=utf-8

input_file="doc.md"
metadata="metadata.yml"
reader_args=(-f markdown)
writer_args=(-t html --standalone --self-contained)

cat "${input_file}" | \
pre-knitty "${input_file}" --yaml "$metadata" | \
pandoc "${reader_args[@]}" -t json | \
knitty "${input_file}" "${reader_args[@]}" "${writer_args[@]}" | \
pandoc -f json "${writer_args[@]}" -o "${input_file}.html"

Windows:

chcp 65001 > NUL
set PYTHONIOENCODING=utf-8

set input_file=doc.md
set metadata=metadata.yml
set reader_args=-f markdown
set writer_args=-t html --standalone --self-contained

type "%input_file%" | ^
pre-knitty "%input_file%" --yaml "%metadata%" | ^
pandoc %reader_args% -t json | ^
knitty "%input_file%" %reader_args% %writer_args% | ^
pandoc -f json %writer_args% -o "%input_file%.html"

Jupyter kernel specification in metadata section:

---
kernelspec:
  display_name: R
  language: R
  name: ir
...

Export to Jupyter notebook with cross-references (using pandoc-crossref: download) and execute it:

export PYTHONIOENCODING=utf-8

input_file="doc.md"
metadata="metadata.yml"
reader_args=(-f markdown)
jupymd="markdown-bracketed_spans-fenced_divs-link_attributes-simple_tables\
-multiline_tables-grid_tables-pipe_tables-fenced_code_attributes\
-markdown_in_html_blocks-table_captions-smart"
writer_args=(-t "$jupymd" --standalone --self-contained --filter pandoc-crossref)

cat "${input_file}" | \
pre-knitty "${input_file}" --yaml "$metadata" | \
pandoc "${reader_args[@]}" -t json | \
knitty "${input_file}" "${reader_args[@]}" "${writer_args[@]}" --to-ipynb | \
pandoc -f json "${writer_args}" | \
post-knitty --to-ipynb | \
jupyter nbconvert --to notebook --execute --stdin --stdout > \
"${input_file}.ipynb"

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
knitty-0.4.14.tar.gz (58.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page