MyNixOS website logo
Description

Convert between Haskell, Markdown, Literate Haskell, TeX.

See the README.md

lima

Sync your README with your Haskell codebase.

Supported formats

Convert files between:

  • Haskell (.hs)
  • Literate Haskell (.lhs)
  • GitHub Flavored Markdown (.md)
  • TeX (.tex)

Related works

  • LiterateMarkdown - lima is a fork of this abandoned project.

  • pandoc - supportsLiterate Haskell and a ton of other formats.

  • IHaskell - create Jupyter notebooks with Haskell code cells and GitHub Flavored Markdown text cells.

  • lhs2tex - convert Literate Haskell to TeX.

  • agda2lagda - Generate a literate Agda/Haskell script from an Agda/Haskell script. Produces LaTeX or Markdown literate scripts.

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

  • unlit - Tool to convert literate code between styles or to code.

  • design-tools - a Pandoc filter for building a book from Markdown.

Scope

lima focuses on converting documents between formats and allows to concatenate documents.

Other scenarios, e.g., inlining a document into a document, may require specialized tools.

Demo

Markdown

.hs and .md

demo

TeX

.hs and .lhs and .tex

demo

Ideas

  • A document is a text in a supported format.
  • I introduced tags into supported formats.
    • E.g., in .hs documents, tags are multiline comments written on a single line like '{- LIMA_ENABLE -}'.
  • Tag names are configurable.
    • A user may set 'on' instead of 'LIMA_ENABLE'.
  • A document can be parsed into a list of tokens.
  • Tags affect document parsing.
  • The tokens can be printed back to that document.
  • Formatting a document is printing a parsed document back to itself.
    • Formatting is idempotent. In other words, formatting the document again won't change its content.
  • The lima library provides a parser and a printer for each supported format.
  • A composition of a printer after a parser produces a converter.
  • Such a converter is usually invertible for a formatted document.
    • Converting a document A to a document B, then converting B to A doesn't change the content of A.

Suggested setup

  1. Create a test suite. README.hs may be its main file.

  2. Add lima and text to its dependencies.

  3. Create a test module. It may have the following content.

    import Lima.Converter (Format (..), convertTo, def)
    import Data.Text.IO qualified as T
    
    main :: IO ()
    main = T.readFile "README.hs" >>= T.writeFile "README.md" . (Hs `convertTo` Md) def
    

This package has three such test suites:

Suggested workflow

Here's a suggested workflow for Haskell and Markdown:

  1. Edit the code in a README.hs using Haskell Language Server.
  2. Convert README.hs to a README.md. Comments from README.hs become text in README.md.
  3. Edit the text in README.md using markdownlint.
  4. Convert README.md back to the README.hs to keep files in sync. Text from README.md becomes comments in README.hs.
  5. Repeat.

Contribute

Clone this repo and enter lima.

git clone https://github.com/deemp/lima
cd lima

cabal

Build

cabal update
cabal build

nix

  1. InstallNix.

  2. Run a devshell and build lima using the project's cabal:

    nix develop nix-dev/
    cabal build
    
  3. Optionally, start VSCodium:

    nix run nix-dev/#writeSettings
    nix run nix-dev/#codium .
    
  4. Open a Haskell file there, hover over a term and wait until HLS shows hints.

  5. Troubleshoot if necessary.

Metadata

Version

0.3.0.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