shr-tag-code-highlight
is a tag render extension (external render function) for the shr emacs HTML engine, which adds syntax highlighting to `code`` blocks.
The main target is to highlight markdown-live-preview-mode
GFM code fences as converted by pandoc when viewed in eww.
It is based on the example provided Andreas Jansson's language-detection.el README and inspired by Chunyang Xu's shr-tag-pre-highlight.el, with some differences:
- targets
code
blocks, notpre
. pandoc generatescode
blocks wrapped inpre
, so it does not make sense to override at thepre
level. - it uses
dom-texts
to grab thecode
block content andshr-insert
to insert it to the highlighted temp buffer instead ofshr-generic
, which would set links ids markers incorrectly and crash the conversion.
Before | After |
---|---|
![]() |
![]() |
This package is not available in melpa yet.
If you use quelpa, you can do:
(quelpa '(shr-tag-code-highlight :fetcher github :repo "dmacvicar/shr-tag-code-highlight.el")
:after shr
:config
(add-to-list 'shr-external-rendering-functions
'(code . shr-tag-code-highlight)))
For Doom Emacs:
(package! shr-tag-code-highlight
:recipe (:host github :repo "dmacvicar/shr-tag-code-highlight.el"))
(use-package! shr-tag-code-highlight
:after shr
:config
(add-to-list 'shr-external-rendering-functions
'(code . shr-tag-code-highlight)))
- Copyright (C) 2021 Duncan Mac-Vicar P.
- Copyright (C) 2016 Andreas Jansson
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.