Coder Social home page Coder Social logo

lsmor / pandoc-lhs-to-ipynb Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 27 KB

A lua filter to convert literate haskell files to jupyter notebooks

License: GNU General Public License v3.0

Haskell 9.47% Lua 0.56% Jupyter Notebook 16.89% HTML 73.07%

pandoc-lhs-to-ipynb's Introduction

Literate Haskell to Jupyter Notebook

This repository contains a few examples on how to convert Literate Haskell files to other formats. It includes a very small lua filter which allows conversion from Literate Haskell files to jupyter notebooks.

pandoc -s \
       --from markdown+lhs \                   # set the source style as markdown with Literate Haskell rules
       --to ipynb \                            # set target style as a jupter notebook
       --lua-filter path/to/lhs-to-ipynb.lua \ # tell pandoc to use this lua filter. Pandoc includes a lua interpreter, so no need to extra deps.
       -o path/to/output.ipynb \               # output file path
       path/to/input.lhs                       # intput file path

This filter is so simple that probably can be achive with a command line option, but I am too lazy to investigate it

Other styles

For output format can be other than ipynb don't use this filter, as it will prevent code style. In example folder there are markdown and html outputs generated with

  • lhs to regular markdown
# Force atx header to avoid underliying level 1 and two headers
pandoc -s --markdown-headings=atx --from markdown+lhs --to markdown -o example/literate.md example/literate.lhs
  • lhs to html
pandoc -s --from markdown+lhs --to html -o example/literate.html example/literate.lhs

Syntactic considerations

Literate comments should be written in markdown style with the following conventions:

  • Use a yaml header to specify ihaskell kernel
  • Markdown headers should be marked with = instead of # because hashtag is interpreted by haskell compiler as number line token
  • Haskell code can be introduced either by > or in between begin{code} ... \end{code} following haskell report
  • Notice that both styles are valid for pandoc even if they are mixed within the same lhs file, but ghci wont load mixed style code.
  • Markdown's quoteblocks syntax collapse with Bird-style Literate Haskell as symbol > is used by both of them.
  • Luckily ghc interprets > as Haskell code, if and only if > is in the first column, so use [space]> to write a markdown quoteblock.
  • Always surround Haskell code by blank lines. This is not required by either ghc nor pandoc but it might cause some undesired edge cases: for example a quoteblock followed by haskell code is wrongly interpreted as a single quoteblock.

In folder example you can find a Literate Haskell file literate.lhs and the corresponding jupyter notebook generated with pandoc

Hakyll Integration

The main purpose of this repo is to serve as example on markdown + lhs files as I couldn't find good/updated info about it on internet. Hakyll is capable of reading and compiling Literate Haskell files using the standard Hakyll.pandocCompiler converting them into html. This makes Literate Haskell files a good candidate for writing and sharing your Haskell blogs.

pandoc-lhs-to-ipynb's People

Contributors

lsmor avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.