emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/devdocs 5768999: Fontify pre tags


From: ELPA Syncer
Subject: [elpa] externals/devdocs 5768999: Fontify pre tags
Date: Fri, 4 Jun 2021 13:57:06 -0400 (EDT)

branch: externals/devdocs
commit 57689994a0008c8d2ee45e34f832bfe12bebb202
Author: Johann Klähn <johann@jklaehn.de>
Commit: Augusto Stoffel <arstoffel@gmail.com>

    Fontify pre tags
    
    `devdocs.io` uses `pre` tags with `data-language` attributes to annotate
    code blocks that should be syntax highlighted.
    
    Copyright-paperwork-exempt: yes
---
 devdocs.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/devdocs.el b/devdocs.el
index 56e9182..5658806 100644
--- a/devdocs.el
+++ b/devdocs.el
@@ -34,6 +34,7 @@
 
 ;;; Code:
 
+(require 'org-src)
 (require 'seq)
 (require 'shr)
 (eval-when-compile
@@ -273,6 +274,16 @@ with the order of appearance in the text."
     ('?# (concat (devdocs--path-file base) path))
     (_ (concat (file-name-directory base) path))))
 
+(defun devdocs--shr-tag-pre (dom)
+  "Insert and fontify pre-tag represented by DOM."
+  (let ((shr-folding-mode 'none) (shr-current-font 'default) start)
+    (shr-ensure-newline)
+    (setq start (point))
+    (shr-generic dom)
+    (when-let ((lang (dom-attr dom 'data-language)))
+      (org-src-font-lock-fontify-block (downcase lang) start (point)))
+    (shr-ensure-newline)))
+
 (defun devdocs--render (entry)
   "Render a DevDocs documentation entry, returning a buffer.
 
@@ -286,6 +297,9 @@ fragment part of ENTRY.path."
       (devdocs-mode))
     (let-alist entry
       (let ((buffer-read-only nil)
+            (shr-external-rendering-functions
+             (cons '(pre . devdocs--shr-tag-pre)
+              shr-external-rendering-functions))
             (file (expand-file-name (format "%s/%s.html" .doc 
(url-hexify-string
                                                                
(devdocs--path-file .path)))
                                     devdocs-data-dir)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]