Skip to main content

Reproducible report generation tool via Jupyter, Pandoc and Markdown. Contains fork of the Notedown.

Project description

Knitty

Build Status

Knitty is a Pandoc filter and Atom/Hydrogen-friendly reproducible report generation tool via Jupyter, Pandoc and Markdown (fork of the Stitch). Insert python code (or other Jupyter kernel code) to the Markdown document and have code's results in the output document.

See Knitty documentation.

You can use:

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.

Via conda:

conda install -c defaults -c conda-forge knitty

Via pip:

pip install knitty

Optional install

Modified version of Notedown by Aaron O'Leary is included in Knitty as knotedown. If you would like to use knotedown to import from R Markdown you need installed knitr:

conda install r-knitr r-reticulate

Usage

You either can use Knitty as a standard Pandoc filter:

cat doc.md | pre-knitty | pandoc --filter knitty -o doc.ipynb

and specify some subset of Knitty options in metadata: self_contained: True, standalone: True. But this way you cannot switch from Markdown to RST for example.

Or you can set all Knitty options (including those in metadata) by using it as a Pandoc filter with multiple arguments ($t is an arg that Pandoc passes to it's filters):

Unix:

export LANG=C.UTF-8
export PYTHONIOENCODING=utf-8

in=doc.md
R=(-f markdown)
W=(-t html --standalone --self-contained)

t="$(pandoc-filter-arg "${W[@]}")"
cat "$in" | pre-knitty |
pandoc "${R[@]}" -t json |
knitty $t "$in" "${R[@]}" "${W[@]}" |
pandoc -f json "${W[@]}" -o "$in.html"

Windows (see setvar):

chcp 65001 > NUL
set PYTHONIOENCODING=utf-8

set in=doc.md
set R=-f markdown
set W=-t html --standalone --self-contained

pandoc-filter-arg %W% | call .\setvar t
type "%in%" | pre-knitty | ^
pandoc %R% -t json | ^
knitty %t% "%in%" %R% %W% | ^
pandoc -f json %W% -o "%in%.html"

Before v0.5.0 Knitty supported conversion to .ipynb via Notedown but since v0.5.0 it is adapted to be used with Pandoc >=2.6. You can learn how to convert to ipynb via Pandoc here (optionally: install Pandoc in Python). I also recommend using knitty.self_contained_raw_html_img Panflute filter (see here) to fix Pandoc attachments created when to .ipynb conversion.

Worth mentioning that you can use Knitty together with pandoc-crossref (see install instructions). You may also need to tune output format in Pandoc and execute the notebook. See example without Knitty:

pandoc doc.md --filter pandoc-crossref --to "ipynb-bracketed_spans-fenced_divs\
-link_attributes-simple_tables-multiline_tables-grid_tables-pipe_tables\
-fenced_code_attributes-markdown_in_html_blocks-table_captions-smart" | \
jupyter nbconvert --to notebook --execute --stdin --stdout > doc.ipynb

Project details


Download files

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

Source Distribution

knitty-0.5.3.tar.gz (57.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page