• Stars
    star
    125
  • Rank 277,407 (Top 6 %)
  • Language
    Haskell
  • License
    MIT License
  • Created over 11 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Literate Haskell support for Markdown

Literate Haskell support for Markdown

markdown-unlit is a custom unlit program. It can be used to extract Haskell code from Markdown files.

To use it with GHC, add

ghc-options: -pgmL markdown-unlit

to your cabal file.

Extended example

tl;dr markdown-unlit allows you to have a README.md, that at the same time is a literate Haskell program.

The following steps show you how to set things up, so that:

  • the Haskell code in your README.md gets syntax highlighted on GitHub
  • you can run your literate Haskell within GHCi
  • you can create a Cabal test-suite from your README.md (no broken code examples anymore, yay!)

The complete code of this example is provided in the example subdirectory.

1. Install markdown-unlit

$ cabal update && cabal install markdown-unlit

2. Create a README.md

# nifty-library: Do nifty things (effortlessly!)

Here is a basic example:

```haskell
main :: IO ()
main = putStrLn "That was easy!"
```

Code blocks with class haskell are syntax highlighted on GitHub (like so).

3. Create a symbolic link README.lhs -> README.md

$ ln -s README.md README.lhs

4. Run your code

At this point we can load the code into GHCi:

$ ghci -pgmL markdown-unlit README.lhs
*Main> main
That was easy!

Or better yet, pipe the required flag into a .ghci file, and forget about it:

$ echo ':set -pgmL markdown-unlit' >> .ghci
$ ghci README.lhs
*Main> main
That was easy!

5. Create a Cabal test-suite

name:             nifty-library
version:          0.0.0
build-type:       Simple
cabal-version:    >= 1.8

library
  -- nothing here yet

test-suite readme
  type:           exitcode-stdio-1.0
  main-is:        README.lhs
  build-depends:  base, markdown-unlit
  ghc-options:    -pgmL markdown-unlit
  build-tool-depends: markdown-unlit:markdown-unlit

Run it like so:

$ cabal configure --enable-tests && cabal build && cabal test

Customizing

By default, markdown-unlit extracts all code that is marked with haskell, unless it is marked with ignore as well. You can customize this by passing -optL <pattern> to GHC.

A simple pattern is just a class name, e.g.:

-optL foo

extracts all code that is marked with foo.

A class name can be negated by prepending it with a !, e.g.

-optL !foo

extracts all code, unless it is marked with foo.

You can use + to combine two patterns with AND, e.g.

-optL foo+bar

extracts all code that is marked with both foo and bar.

If -optL is given multiple times, the patterns are combined with OR, e.g.

-optL foo -optL bar

extracts all code that is either marked with foo or bar.

Development

Limitations

If you want to get any limitation lifted, open a ticket or send a pull request.

Contributing

Add tests for new code, and make sure that the test suite passes with your modifications.

cabal configure --enable-tests && cabal build && cabal test

Real world examples

That's it, have fun!

More Repositories

1

hpack

hpack: A modern format for Haskell packages
Haskell
612
star
2

doctest

An implementation of Python's doctest for Haskell
Haskell
369
star
3

tinc

A dependency manager for Haskell
Haskell
97
star
4

aeson-qq

JSON quasiquoter for Haskell
Haskell
78
star
5

reserve

Universal and robust reloading for Haskell web applications
Haskell
70
star
6

pwsafe

A command-line password manager
Haskell
31
star
7

interpolate

String interpolation for Haskell done right!
Haskell
31
star
8

v8

Haskell bindings to Google's V8 JavaScript Engine
Haskell
14
star
9

logging-facade

An experimental logging API for Haskell, inspired by slf4j
Haskell
11
star
10

mpd

Mirror of git://git.musicpd.org/master/mpd.git
C
11
star
11

cucumber-haskell

Cucumber for Haskell
9
star
12

hspec-tutorial

Developing a tiny time-service with WAI and Hspec
Haskell
7
star
13

with-location

DEPRECATED, use https://github.com/sol/call-stack instead
Haskell
6
star
14

haskell-platform-versions-comparison-chart

NOTE: This project is superseded by http://www.haskell.org/platform/changelog.html
Haskell
6
star
15

rewrite-with-location

Proposal: A simple and extensible mechanism for source locations in library code
Haskell
6
star
16

haskell-autotag

A GitHub Action that creates a Git tag on .cabal version bumps
Haskell
5
star
17

http-kit

A low-level HTTP library
Haskell
5
star
18

pandoc-unlit

Literate Haskell support for GitHub's Markdown flavor
Haskell
5
star
19

aenea-box

Linux speech recognition setup based on Vagrant, Aenea, Dragonfly, NatLink and Dragon
Makefile
5
star
20

strafunski

Mirror of http://code.google.com/p/strafunski/
Haskell
4
star
21

hspec-test-framework

Run test-framework tests with Hspec
Haskell
4
star
22

HackageOneFive

Reverse dependency lookup for all packages on Hackage
Haskell
4
star
23

inject

Inject the output of shell commands into arbitrary text templates
Haskell
3
star
24

call-stack

Use GHC call-stacks in a backward compatible way
Haskell
3
star
25

solid

A functional scripting environment
Haskell
3
star
26

attoparsec-parsec

An Attoparsec compatibility layer for Parsec
Haskell
3
star
27

hspec-shouldbe

Convenience wrapper and utilities for hspec
Vim Script
3
star
28

stringbuilder

A writer monad for multi-line string literals
Haskell
3
star
29

hackage-jsonp

Latest package versions on Hackage as JSONP
Haskell
2
star
30

json-fu

JSON serialization / deserialization
Haskell
2
star
31

darcs-mirrors

Haskell
2
star
32

string

An effort to provide all functions from Data.Text for strings
Haskell
2
star
33

GHC2021

Use GHC2021 with existing versions of GHC
2
star
34

logsink

A logging framework for Haskell
Haskell
2
star
35

test-framework-spec

A DSL for building Hspec/RSpec style test suites for test-framework
Haskell
2
star
36

stats

Haskell
2
star
37

haskell-code-edit

Haskell
2
star
38

infer-license

Infer software license from a given license file
Haskell
2
star
39

mpdinfo

A libmpd-haskell toy project, prints the currently played song and elapsed time
Haskell
2
star
40

format

String interpolation for Haskell
Haskell
2
star
41

get-bootstrapped

Stable links for bootstrap releases
JavaScript
2
star
42

config-ng

Format preserving parser and renderer for INI-style config files
Haskell
2
star
43

run-haskell-tests

2
star
44

depends

A simple configuration management tool for Haskell
Haskell
2
star
45

display

Convert Haskell values to a textual representation
Haskell
2
star
46

ghc-env

Automatically download and manage multiple versions of GHC
Haskell
2
star
47

uu-parsinglib

A mirror of uu-parsinglib's svn repository
Haskell
2
star
48

qreadline

A drop-in replacement for QLineEdit with emacs-like key bindings
C++
1
star
49

ci

Haskell
1
star
50

cg1

A simple OpenGL application
C++
1
star
51

setenv

A cross-platform Haskell library for setting environment variables
Haskell
1
star
52

rest-client

Haskell
1
star
53

aeson-toolkit

A generalization of Aeson over Failure
Haskell
1
star
54

fancontrol

Minimalistic fan control for my x200
Haskell
1
star
55

hexpat

A mirror of http://code.haskell.org/hexpat/
C
1
star
56

json-stream

Haskell
1
star
57

KBDevBoard

A development board for rapid prototyping of keyboard circuitry âš¡
1
star
58

conduit-issue

Haskell
1
star
59

better-process

A *better* incarnation of Haskell's `process` library
Haskell
1
star
60

simdjson

Haskell
1
star
61

hspec-experimental

An experimental DSL for testing on top of Hspec
Haskell
1
star