MyNixOS website logo
Description

Interactive literate programming.

Evaluate markdown code blocks to show the results of running the code.

inliterate: Dynamic reporting for Haskell

The aim of inliterate is generate dynamic markdown reports from literate Haskell code in which code blocks can be evaluated to present the results of analyses in textual or graphical form.

inliterate is a GHC preprocessor which transforms a markdown document into a Haskell program, which, when run, prints to stdout the input document in HTML format. Certain code blocks with special annotations can be treated in particular ways: as Haskell code that must be included in the generating program (at the top level or in a do block) and as code that must be evaluated with the results inserted into the HTML document.

For an example document, see https://github.com/diffusionkinetics/open/blob/master/plotlyhs/gendoc/GenDocInlit.hs which ccompiles into https://glutamate.github.io/plotlyhs/.

The inliterate document

The inliterate ddocument should contain the following pragma on the first line or after the LANGUAGE pragmas:

{-# OPTIONS_GHC -F -pgmF inlitpp #-}

this tells GHC to invoke the preprocessor.

Code blocks

inliterate gives special meaning to the following code block language annotations (see the plotlyhs documentation generator to see how these are invoked)

html_header

this HTML should go in the header. Use this to load JavaScript or CSS, for instance for graphing libraries.

haskell top

Haskell code that is added to the top level

haskell do

Haskell code that is added to the main do block. use this for loading data or otherwise performing input and output.

haskell eval

Haskell code that is evaluated. The resultant type must be an instance of the AskInliterate class ddefined in Inliterate.Import.

hide

add this to top or do code to prevent it from being printed in the output document (but it is still run)

How to run

As an excutable

if you only have a few documents, you can put them in your cabal file as an executable, with inliterate as a build dependency.

here's the example from the plotlyhs documentation generator:

executable plotly-gendoc
  main-is: GenDocInlit.hs
  build-depends:       base >=4.6 && <5
                     , plotlyhs
                     , lucid
                     , aeson
                     , text
                     , microlens
                     , plotlyhs
                     , inliterate
                     , datasets
                     , neat-interpolation

Using stack runghc

if you have a larger number, or dynamically changing, set of documents, you can run them individually using stack runghc. inliterate should be listed in your cabal file as a build dependency to make sure the package is visible.

stack runghc InliterateFile.hs

if you want only the body HTML and not the headers, you can pass the argument --no-inlit-wrap to the executable

stack runghc InliterateFile.hs -- --no-inlit-wrap
Metadata

Version

0.1.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows