aboutsummaryrefslogtreecommitdiffstats
path: root/oni-shr.el
diff options
context:
space:
mode:
authorGravatar Tom Willemse2020-03-28 11:50:44 -0700
committerGravatar Tom Willemse2020-03-28 11:51:28 -0700
commit931f38989eff3d8ecc09aa030d2d6ee1aade883d (patch)
treec2029ad61d4bb716daa051667f372c7e507155af /oni-shr.el
parent226c1d86bd3aeee6c07bdeee6facb3039841c3da (diff)
downloademacs-config-931f38989eff3d8ecc09aa030d2d6ee1aade883d.tar.gz
emacs-config-931f38989eff3d8ecc09aa030d2d6ee1aade883d.zip
Improve shr rendering of <code> and <pre> tags a little
Diffstat (limited to 'oni-shr.el')
-rw-r--r--oni-shr.el25
1 files changed, 23 insertions, 2 deletions
diff --git a/oni-shr.el b/oni-shr.el
index 3537fb1..9bc2dfd 100644
--- a/oni-shr.el
+++ b/oni-shr.el
@@ -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))