MyNixOS website logo
Description

Syntax highlighter for Haskell using the lexer of GHC.

GHC syntax highligher

License FreeBSD Hackage Stackage Nightly Stackage LTS CI

This is a syntax highlighter library for Haskell using the lexer of GHC.

Here is a blog post announcing the package, the readme is mostly derived from it:

  • https://markkarpov.com/post/announcing-ghc-syntax-highlighter.html

Motivation

Parsing Haskell is hard, because Haskell is a complex language with countless features. The only way to get it right 100% is to use the parser of GHC itself. Fortunately, now there is the ghc package, which as of version 8.4.1 exports enough of GHC's source code to allow us use its lexer.

Alternative approaches, even decent ones like highlight.js either don't support cutting-edge features or do their work without sufficient precision so that many tokens end up combined and the end result is typically still hard to read.

How to use it in your blog

Depends on your markdown processor. If you're an mmark user, good news, since version 0.2.1.0 of mmark-ext it includes the ghcSyntaxHighlighter extension. Due to flexibility of MMark, it's possible to use this highlighter for Haskell and skylighting as a fall-back for everything else. Consult the docs for more information.

skylighting is what Pandoc uses. And from what I can tell it's hardcoded to use only that library for highlighting, so some creativity may be necessary to get it work.

Limitations

CPP directives are not lexed correctly, because the GHC parser is not designed to parse them.

Contribution

Issues, bugs, and questions may be reported in the GitHub issue tracker for this project.

Pull requests are also welcome.

License

Copyright © 2018–present Mark Karpov

Distributed under BSD 3 clause license.

Metadata

Version

0.0.12.0

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