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

Knitty is 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.

See Knitty documentation.

Install

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

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 six pyyaml
pip install --progress-bar off 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 six 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.

Usage

Unix:

export PYTHONIOENCODING=utf-8

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

cat "${input_file}" | \
pre-knitty "${input_file}" | \
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 reader_args=-f markdown
set writer_args=-t html --standalone --self-contained

type %input_file% | ^
pre-knitty %input_file% | ^
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:

chcp 65001 > NUL
set PYTHONIOENCODING=utf-8

set input_file=doc.md
set reader_args=-f markdown
set 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
set writer_args=-t %jupymd% --standalone --self-contained --filter pandoc-crossref

type %input_file% | ^
pre-knitty %input_file% | ^
pandoc %reader_args% -t json | ^
knitty %input_file% %reader_args% %writer_args% --to-ipynb | ^
pandoc -f json %writer_args% | ^
knotedown --match=in --nomagic > %input_file%.ipynb

jupyter nbconvert --to notebook --execute %input_file%.ipynb

Project details


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.1.tar.gz (55.5 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