@hackage lima0.2.1.1
Convert between Haskell, Markdown, Literate Haskell, TeX
Installation
Dependencies (5)
- base >=4 && <5
- data-default
- microlens
- microlens-th
- text Show all…
Dependents (1)
@hackage/fields-and-cases
lima
Convert between files in different formats.
Related works
-
LiterateMarkdown -
limais a fork of this (abandoned?) project. -
pandoc - supports
Literate Haskelland a ton of other formats. -
IHaskell - create
Jupyternotebooks withHaskellcode cells andGitHub Flavored Markdowntext cells and do much more. -
lhs2tex - convert
Literate HaskelltoTeX.
Supported formats
Haskell(.hs)Literate Haskell(.lhs)GitHub Flavored Markdown(.md)TeX(.tex)
Demo
Markdown

TeX

Ideas
- I introduced tags into supported formats.
- E.g., in
.hsfiles, tags are multiline comments written on a single line like{- LIMA_ENABLE -}.
- E.g., in
- Tag names are configurable.
- A user may set
oninstead ofLIMA_ENABLE.
- A user may set
- A document can be parsed into a list of tokens.
- Tags affect how a document is parsed.
- 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
limalibrary 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
Ato a documentB, then convertingBtoAdoesn't change the content ofA.
- Converting a document
Setup
-
Create a test suite.
-
Add
limaandtextto its dependencies. -
Create a test module. It can have the following content.
import 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
Example
This package has two such test suites:
- readme-hs-to-md converts
README.hstoREADME.md - readme-md-to-hs converts
README.mdtoREADME.hs
Workflow
Here's a possible workflow for Haskell and Markdown:
- Edit the code in a
README.hsusing Haskell Language Server. - Convert
README.hsto aREADME.md. Comments fromREADME.hsbecome text inREADME.md. - Edit the text in
README.mdusing markdownlint. - Convert
README.mdback to theREADME.hsto keep files in sync. Text inREADME.mdbecomes comments inREADME.hs. - Repeat.
Contribute
Clone this repo and enter lima
git clone https://github.com/deemp/lima
cd lima
cabal
Build
cabal update
cabal build
nix
-
Install
Nix. -
Run a devshell and build
limausing the project'scabal:nix develop nix-dev/ cabal build -
Optionally, start
VSCodium:nix run nix-dev/#writeSettings nix run nix-dev/#codium . -
Open a
Haskellfile there, hover over a term and wait untilHLSshows hints. -
Troubleshoot if necessary.