unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jeremy Friesen <jeremy.n.friesen@gmail.com>
To: 50223@debbugs.gnu.org
Subject: bug#50223: Add new shr faces and rendering functions
Date: Thu, 26 Aug 2021 21:58:35 -0400	[thread overview]
Message-ID: <CALSSkZvugqEofBGF-ioKpipcgsEtLdnNSt9QcHepQt_HTm1cHQ@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 541 bytes --]

Per conversations with larsi@gnus.org, I'm submitting a patch for adding
the following to SHR:

    * lisp/net/shr.el (shr-tag-cite): Add <CITE> tag
    * lisp/net/shr.el (shr-tag-dfn): Add <DFN> tag
    * lisp/net/shr.el (shr-tag-small): Add <SMALL> tag
    * lisp/net/shr.el (shr-tag-time): Add <TIME> tag
    * lisp/net/shr.el (shr-tag-q): Add <Q> tag
    * lisp/net/shr.el (shr-around-q-tag): New defcustom
    * lisp/net/shr.el (shr-time): New defface
    * lisp/net/shr.el (shr-small): New defface

-- 

Jeremy Friesen
takeonrules.com

[-- Attachment #1.2: Type: text/html, Size: 1357 bytes --]

[-- Attachment #2: 0002-Add-new-shr-faces-and-rendering-functions.patch --]
[-- Type: application/octet-stream, Size: 3453 bytes --]

From f73824a175ef6067d3bc5ee5930b552bbf25da25 Mon Sep 17 00:00:00 2001
From: Jeremy Friesen <jeremy.n.friesen@gmail.com>
Date: Thu, 26 Aug 2021 17:05:52 -0400
Subject: [PATCH] Add new shr faces and rendering functions

* lisp/net/shr.el (shr-tag-cite): Add <CITE> tag
* lisp/net/shr.el (shr-tag-dfn): Add <DFN> tag
* lisp/net/shr.el (shr-tag-small): Add <SMALL> tag
* lisp/net/shr.el (shr-tag-time): Add <TIME> tag
* lisp/net/shr.el (shr-tag-q): Add <Q> tag
* lisp/net/shr.el (shr-around-q-tag): New defcustom
* lisp/net/shr.el (shr-time): New defface
* lisp/net/shr.el (shr-small): New defface
---
 lisp/net/shr.el                    | 45 ++++++++++++++++++++++++++++++
 test/lisp/net/shr-resources/q.html |  1 +
 test/lisp/net/shr-resources/q.txt  |  1 +
 3 files changed, 47 insertions(+)
 create mode 100644 test/lisp/net/shr-resources/q.html
 create mode 100644 test/lisp/net/shr-resources/q.txt

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 85d81b6bbc..dbb45c3ff1 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -128,6 +128,14 @@ Alternative suggestions are:
   :version "24.4"
   :type 'string)
 
+(defcustom shr-around-q-tag '("\"" . "\"")
+  "The before and after quotes for a Q-tag.
+- `car' is inserted before the Q-tag
+- `cdr' is inserted after the Q-tag.
+Alternative suggestions are: - '(\"“\" . \"”\")"
+  :version "28.1"
+  :type (cons 'string 'string))
+
 (defcustom shr-cookie-policy 'same-origin
   "When to use cookies when fetching dependent data like images.
 If t, always use cookies.  If nil, never use cookies.  If
@@ -183,6 +191,16 @@ temporarily blinks with this face."
   "Face for <abbr> elements."
   :version "27.1")
 
+(defface shr-time
+  '((t :inherit underline :underline (:style wave)))
+  "Face for <time> elements."
+  :version "28.1")
+
+(defface shr-small
+  '((t :height 0.8))
+  "Face for <small> elements."
+  :version "28.1")
+
 (defface shr-h1
   '((t :height 1.3 :weight bold))
   "Face for <h1> elements."
@@ -1498,9 +1516,36 @@ ones, in case fg and bg are nil."
 (defun shr-tag-em (dom)
   (shr-fontize-dom dom 'italic))
 
+(defun shr-tag-cite (dom)
+  (shr-fontize-dom dom 'italic))
+
+(defun shr-tag-dfn (dom)
+  (shr-fontize-dom dom 'italic))
+
 (defun shr-tag-strong (dom)
   (shr-fontize-dom dom 'bold))
 
+(defun shr-tag-small (dom)
+  (shr-fontize-dom dom (if shr-use-fonts 'shr-small)))
+
+(defun shr-tag-q (dom)
+  (shr-insert (car shr-around-q-tag))
+  (shr-generic dom)
+  (shr-insert (cdr shr-around-q-tag)))
+
+(defun shr-tag-time (dom)
+    (when-let* ((datetime (or
+                           (dom-attr dom 'title)
+                           (dom-attr dom 'datetime)))
+	        (start (point)))
+      (shr-generic dom)
+      (shr-add-font start (point) 'shr-time)
+      (add-text-properties
+       start (point)
+       (list
+        'help-echo datetime
+        'mouse-face 'highlight))))
+
 (defun shr-tag-u (dom)
   (shr-fontize-dom dom 'underline))
 
diff --git a/test/lisp/net/shr-resources/q.html b/test/lisp/net/shr-resources/q.html
new file mode 100644
index 0000000000..e60e8e39a6
--- /dev/null
+++ b/test/lisp/net/shr-resources/q.html
@@ -0,0 +1 @@
+<q>Hello World</q>
\ No newline at end of file
diff --git a/test/lisp/net/shr-resources/q.txt b/test/lisp/net/shr-resources/q.txt
new file mode 100644
index 0000000000..be5d95a193
--- /dev/null
+++ b/test/lisp/net/shr-resources/q.txt
@@ -0,0 +1 @@
+"Hello World"
\ No newline at end of file
-- 
2.31.1


             reply	other threads:[~2021-08-27  1:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27  1:58 Jeremy Friesen [this message]
2021-11-06  1:08 ` bug#50223: Add new shr faces and rendering functions Lars Ingebrigtsen
2022-03-22 22:58   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALSSkZvugqEofBGF-ioKpipcgsEtLdnNSt9QcHepQt_HTm1cHQ@mail.gmail.com \
    --to=jeremy.n.friesen@gmail.com \
    --cc=50223@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).