1
0
Fork 0

Improve shr rendering of <code> and <pre> tags a little

This commit is contained in:
Tom Willemse 2020-03-28 11:50:44 -07:00
parent 226c1d86bd
commit 931f38989e

View file

@ -4,7 +4,7 @@
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2019.0904.210815
;; Version: 2020.0328.023508
;; 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
@ -33,8 +33,29 @@
(butlast args)
args))
(defun shr-tag-code (dom)
"Render a <code> tag from DOM."
(let ((shr-current-font 'default)
(start (point)))
(shr-generic dom)
(add-face-text-property start (point) '(:background "#222222" :box (:line-width 3 :color "#222222")))))
(defun oni-shr--recolorize (orig-fun &rest args)
"Do some custom colorization.
This should be used with add-function with the :around
combinator. ORIG-FUN is the original function being wrapped, ARGS
are the arguments passed in to it."
(let ((start (point)))
(apply orig-fun args)
(save-excursion
(forward-line -1)
(string-rectangle start (point) " "))
(add-face-text-property start (point) '(:background "#222222"))))
(advice-add #'shr-colorize-region
:filter-args #'oni-shr--colorize-remove-last-arg)
:filter-args #'oni-shr--colorize-remove-last-arg)
(add-function :around (symbol-function 'shr-tag-pre) #'oni-shr--recolorize)
;;;###autoload(with-eval-after-load 'shr (require 'oni-shr))