Syntax highlighter for Haskell using the lexer of GHC
Haskell
59
112 commits
updated Aug 1, 2026
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:
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 to 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.
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 the 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 to work.
CPP directives are not lexed correctly, because the GHC parser is not designed to parse them.
Issues, bugs, and questions may be reported in the GitHub issue tracker for this project.
Pull requests are also welcome.
Copyright © 2018–present Mark Karpov
Distributed under the BSD 3-clause license.
Haskell
100.0%
Syntax highlighter for Haskell using the lexer of GHC
Haskell
59
112 commits
updated Aug 1, 2026
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:
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 to 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.
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 the 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 to work.
CPP directives are not lexed correctly, because the GHC parser is not designed to parse them.
Issues, bugs, and questions may be reported in the GitHub issue tracker for this project.
Pull requests are also welcome.
Copyright © 2018–present Mark Karpov
Distributed under the BSD 3-clause license.
Haskell
100.0%