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

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

[nongnu] elpa/htmlize a0b55cb 112/134: Introduced option for styling <pr


From: ELPA Syncer
Subject: [nongnu] elpa/htmlize a0b55cb 112/134: Introduced option for styling <pre>, "screenshot" function.
Date: Sat, 7 Aug 2021 09:17:18 -0400 (EDT)

branch: elpa/htmlize
commit a0b55cba65a225df8d9e17a3ac448ce9e8ec962d
Author: Tamas K. Papp <tkpapp@gmail.com>
Commit: Hrvoje Nikšić <hniksic@gmail.com>

    Introduced option for styling <pre>, "screenshot" function.
    
    This makes inline-css and font decoration for <pre> optional, and
    disabled by default, preserving the original behavior before this PR.
    
    A new function htmlize-region-save-screenshot turns this on and saves
    the resulting HTML in the kill ring (which is most convenient for
    pasting into blog posts etc). This should allow a best approximation
    for capturing "screenshots" of a region in HTML.
---
 htmlize.el | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/htmlize.el b/htmlize.el
index 8abf183..71bf0fb 100644
--- a/htmlize.el
+++ b/htmlize.el
@@ -314,6 +314,13 @@ Set this to nil if you prefer the default (fundamental) 
mode."
                 (function :tag "User-defined major mode"))
   :group 'htmlize)
 
+(defcustom htmlize-pre-style nil
+  "When non-nil, `<pre>' tags will be decorated with style
+information in `font' and `inline-css' modes. This allows a
+consistent background for captures of regions."
+  :type 'boolean
+  :group 'htmlize)
+
 (defvar htmlize-before-hook nil
   "Hook run before htmlizing a buffer.
 The hook functions are run in the source buffer (not the resulting HTML
@@ -1557,9 +1564,11 @@ it's called with the same value of KEY.  All other 
times, the cached
                     " ")))
 
 (defun htmlize-inline-css-pre-tag (face-map)
-  (format "<pre style=\"%s\">"
-         (mapconcat #'identity (htmlize-css-specs (gethash 'default face-map))
-                    " ")))
+  (if htmlize-pre-style
+      (format "<pre style=\"%s\">"
+              (mapconcat #'identity (htmlize-css-specs (gethash 'default 
face-map))
+                         " "))
+    (format "<pre>")))
 
 (defun htmlize-inline-css-text-markup (fstruct-list buffer)
   (let* ((merged (htmlize-merge-faces fstruct-list))
@@ -1586,10 +1595,12 @@ it's called with the same value of KEY.  All other 
times, the cached
            (htmlize-fstruct-background fstruct))))
 
 (defun htmlize-font-pre-tag (face-map)
-  (let ((fstruct (gethash 'default face-map)))
-    (format "<pre text=\"%s\" bgcolor=\"%s\">"
-           (htmlize-fstruct-foreground fstruct)
-           (htmlize-fstruct-background fstruct))))
+  (if htmlize-pre-style
+      (let ((fstruct (gethash 'default face-map)))
+        (format "<pre text=\"%s\" bgcolor=\"%s\">"
+                (htmlize-fstruct-foreground fstruct)
+                (htmlize-fstruct-background fstruct)))
+    (format "<pre>")))
        
 (defun htmlize-font-text-markup (fstruct-list buffer)
   ;; In `font' mode, we use the traditional HTML means of altering
@@ -1836,6 +1847,16 @@ the text to another HTML buffer."
                            (plist-get htmlize-buffer-places 'content-end)))
       (kill-buffer htmlbuf))))
 
+(defun htmlize-region-save-screenshot (beg end)
+  "Save the htmlized (see `htmlize-region-for-paste') region in
+the kill ring. Uses `inline-css', with style information in
+`<pre>' tags, so that the rendering of the marked up text
+approximates the buffer as closely as possible."
+  (interactive "r")
+  (let ((htmlize-pre-style t))
+    (kill-new (htmlize-region-for-paste beg end)))
+  (deactivate-mark))
+
 (defun htmlize-make-file-name (file)
   "Make an HTML file name from FILE.
 



reply via email to

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