Skip to content
Syntax highlighting code block in HTML for shr/eww
Emacs Lisp
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

shr-tag-pre-highlight - Syntax highlighting code block in HTML

Author: Chunyang Xu
Version: 2


This package adds syntax highlighting support for code block in HTML, rendered by shr.el. The probably most famous user of shr.el is EWW (the Emacs Web Wowser).


Before After

In above, I am using EWW to visit And the color theme is sanityinc-tomorrow-eighties, from Steve Purcell's color-theme-sanityinc-tomorrow package


This package is available from MELPA. If you use use-package to manage the init file, use something like the following:

(use-package shr-tag-pre-highlight
  :ensure t
  :after shr
  (add-to-list 'shr-external-rendering-functions
               '(pre . shr-tag-pre-highlight))
  (when (version< emacs-version "26")
    (with-eval-after-load 'eww
      (advice-add 'eww-display-html :around

Why is eww-display-html advised for Emacs version older than 26

Unfortunately, EWW always overrides shr-external-rendering-functions until this commit (2015-12), but Emacs 25.2 (latest release - 2017-4) doesn't include this commit. Thus if you want syntax highlighting in EWW, you have to use devel version of Emacs (also know as emacs-26 at this moment) or advice eww-display-html as above.

Converted from shr-tag-pre-highlight.el by el2markdown.

You can’t perform that action at this time.