* Adding more tags for SHR
@ 2021-08-26 21:19 Jeremy Friesen
2021-08-27 0:17 ` Lars Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Friesen @ 2021-08-26 21:19 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 489 bytes --]
Attached is a patch for more rendering options for SHR.
The CITE, DFN, Q, and SMALL changes align with many browser agent
stylesheets. The TIME exposes the underlying meaningful attributes. You
might have a tag <time datetime="2021-08-26">Today</time> and exposing the
datetime attribute (or title) helps clarify what is meant by "Today".
I'm excited to be submitting my first patch to Emacs core, and hope I've
done my homework to get this right.
--
Jeremy Friesen
takeonrules.com
[-- Attachment #1.2: Type: text/html, Size: 1048 bytes --]
[-- Attachment #2: 0001-Add-new-shr-faces-and-rendering-functions.patch --]
[-- Type: application/octet-stream, Size: 3520 bytes --]
From 8c7cd0ee93bb45cc30f0445187b19d117f41370b 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-before-q-tag): New defcustom
* lisp/net/shr.el (shr-after-q-tag): New defcustom
* lisp/net/shr.el (shr-time): New defface
* lisp/net/shr.el (shr-small): New defface
---
lisp/net/shr.el | 51 ++++++++++++++++++++++++++++++
test/lisp/net/shr-resources/q.html | 1 +
test/lisp/net/shr-resources/q.txt | 1 +
3 files changed, 53 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..9f6a36951f 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -128,6 +128,20 @@ Alternative suggestions are:
:version "24.4"
:type 'string)
+(defcustom shr-before-q-tag "“"
+ "Before quote used for q-tag.
+Alternative suggestions are:
+- \"\\\"\""
+ :version "28.1"
+ :type 'string)
+
+(defcustom shr-after-q-tag "”"
+ "After quote used for q-tag.
+Alternative suggestions are:
+- \"\\\"\""
+ :version "28.1"
+ :type '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 +197,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 +1522,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 shr-before-q-tag)
+ (shr-generic dom)
+ (shr-insert shr-after-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..1b4485eac0
--- /dev/null
+++ b/test/lisp/net/shr-resources/q.txt
@@ -0,0 +1 @@
+“Hello World”
\ No newline at end of file
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Adding more tags for SHR
2021-08-26 21:19 Adding more tags for SHR Jeremy Friesen
@ 2021-08-27 0:17 ` Lars Ingebrigtsen
2021-08-27 1:13 ` Jeremy Friesen
0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-27 0:17 UTC (permalink / raw)
To: Jeremy Friesen; +Cc: emacs-devel
Jeremy Friesen <jeremy.n.friesen@gmail.com> writes:
> Attached is a patch for more rendering options for SHR.
Thanks; looks great!
A couple very minor comments:
> +(defcustom shr-before-q-tag "“"
> + "Before quote used for q-tag.
Perhaps it'd be best to default this to nil and then do something along
the lines of
(shr-insert (or shr-before-q-tag
(if (char-displayable-p ?“) ?“ ?\")))
in -tag-q to ensure that the default is displayable everywhere.
> +(defun shr-tag-time (dom)
> + (when-let* ((datetime (or
Misindented?
This change is larger than what we can apply without getting a copyright
assignment for the FSF.
https://www.gnu.org/licenses/why-assign.en.html
Are you willing to sign such paperwork? If so, here's the paperwork to
get started.
Please email the following information to assign@gnu.org, and we
will send you the assignment form for your past and future changes.
Please use your full legal name (in ASCII characters) as the subject
line of the message.
----------------------------------------------------------------------
REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES
[What is the name of the program or package you're contributing to?]
Emacs
[Did you copy any files or text written by someone else in these changes?
Even if that material is free software, we need to know about it.]
[Do you have an employer who might have a basis to claim to own
your changes? Do you attend a school which might make such a claim?]
[For the copyright registration, what country are you a citizen of?]
[What year were you born?]
[Please write your email address here.]
[Please write your postal address here.]
[Which files have you changed so far, and which new files have you written
so far?]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Adding more tags for SHR
2021-08-27 0:17 ` Lars Ingebrigtsen
@ 2021-08-27 1:13 ` Jeremy Friesen
2021-08-27 1:21 ` Lars Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Friesen @ 2021-08-27 1:13 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 2467 bytes --]
Lars, thank you for the feedback.
I've also sent my information to assign@gnu.org.
I went a slightly different route on the q-tag by having an "around"
defcustom using a cons. I also opted to default to a straight quotes
instead of "curly quotes". I'm uncertain how I can set a :type that is
either a 'string or 'nil. (Though I'm very willing to keep working on this)
Attached is iteration 0002 of the changes.
On Thu, Aug 26, 2021 at 8:18 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
> Jeremy Friesen <jeremy.n.friesen@gmail.com> writes:
>
> > Attached is a patch for more rendering options for SHR.
>
> Thanks; looks great!
>
> A couple very minor comments:
>
> > +(defcustom shr-before-q-tag "“"
> > + "Before quote used for q-tag.
>
> Perhaps it'd be best to default this to nil and then do something along
> the lines of
>
> (shr-insert (or shr-before-q-tag
> (if (char-displayable-p ?“) ?“ ?\")))
>
> in -tag-q to ensure that the default is displayable everywhere.
>
> > +(defun shr-tag-time (dom)
> > + (when-let* ((datetime (or
>
> Misindented?
>
> This change is larger than what we can apply without getting a copyright
> assignment for the FSF.
>
> https://www.gnu.org/licenses/why-assign.en.html
>
> Are you willing to sign such paperwork? If so, here's the paperwork to
> get started.
>
> Please email the following information to assign@gnu.org, and we
> will send you the assignment form for your past and future changes.
>
> Please use your full legal name (in ASCII characters) as the subject
> line of the message.
> ----------------------------------------------------------------------
> REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES
>
> [What is the name of the program or package you're contributing to?]
> Emacs
>
> [Did you copy any files or text written by someone else in these changes?
> Even if that material is free software, we need to know about it.]
>
> [Do you have an employer who might have a basis to claim to own
> your changes? Do you attend a school which might make such a claim?]
>
> [For the copyright registration, what country are you a citizen of?]
>
> [What year were you born?]
>
> [Please write your email address here.]
>
> [Please write your postal address here.]
>
> [Which files have you changed so far, and which new files have you written
> so far?]
>
>
--
Jeremy Friesen
takeonrules.com
[-- Attachment #1.2: Type: text/html, Size: 3477 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Adding more tags for SHR
2021-08-27 1:13 ` Jeremy Friesen
@ 2021-08-27 1:21 ` Lars Ingebrigtsen
0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-27 1:21 UTC (permalink / raw)
To: Jeremy Friesen; +Cc: emacs-devel
Jeremy Friesen <jeremy.n.friesen@gmail.com> writes:
> I've also sent my information to assign@gnu.org.
Great! We'll be notified when the assignment is complete, but to ensure
that we don't forget to apply the patch, could you also send the patch
to the issue tracker (with `M-x submit-emacs-patch', for instance, in
Emacs 28).
> I went a slightly different route on the q-tag by having an "around" defcustom
> using a cons. I also opted to default to a straight quotes instead of "curly
> quotes".
Sure; sounds good, too.
> I'm uncertain how I can set a :type that is either a 'string or 'nil.
Something like:
:type '(choice (const :tag "Default" nil)
string)
But the current cons-of-strings is also fine.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-27 1:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-26 21:19 Adding more tags for SHR Jeremy Friesen
2021-08-27 0:17 ` Lars Ingebrigtsen
2021-08-27 1:13 ` Jeremy Friesen
2021-08-27 1:21 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.