ghc-syntax-highlighter: Syntax highlighter for Haskell using the lexer of GHC

[ bsd3, library, text ] [ Propose Tags ] [ Report a vulnerability ]

Syntax highlighter for Haskell using the lexer of GHC.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
dev

Turn on development settings.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1.0, 0.0.2.0, 0.0.3.0, 0.0.3.1, 0.0.4.0, 0.0.4.1, 0.0.5.0, 0.0.6.0, 0.0.7.0, 0.0.8.0, 0.0.9.0, 0.0.10.0, 0.0.11.0, 0.0.12.0
Change log CHANGELOG.md
Dependencies base (>=4.17 && <5), ghc-lib-parser (>=9.10 && <9.11), text (>=0.2 && <2.2) [details]
Tested with ghc ==9.6.3, ghc ==9.8.2, ghc ==9.10.1
License BSD-3-Clause
Author Mark Karpov <markkarpov92@gmail.com>
Maintainer Mark Karpov <markkarpov92@gmail.com>
Category Text
Home page https://github.com/mrkkrp/ghc-syntax-highlighter
Bug tracker https://github.com/mrkkrp/ghc-syntax-highlighter/issues
Source repo head: git clone https://github.com/mrkkrp/ghc-syntax-highlighter.git
Uploaded by mrkkrp at 2024-06-01T19:17:12Z
Distributions LTSHaskell:0.0.11.0, NixOS:0.0.10.0, Stackage:0.0.12.0
Reverse Dependencies 4 direct, 19 indirect [details]
Downloads 5443 total (56 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-06-01 [all 1 reports]

Readme for ghc-syntax-highlighter-0.0.12.0

[back to package description]

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:

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.