emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 8282c34 1/2: Handle HTML 'ol' start attribute in sh


From: Eli Zaretskii
Subject: [Emacs-diffs] master 8282c34 1/2: Handle HTML 'ol' start attribute in shr.el
Date: Fri, 22 Feb 2019 02:55:42 -0500 (EST)

branch: master
commit 8282c34f0f2f4ad2c4956fc595518da64a7bef1f
Author: Nicholas Drozd <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Handle HTML 'ol' start attribute in shr.el
    
    * lisp/net/shr.el (shr-tag-ol): Don't automatically assume
    1-indexing for all ordered lists, use <ol> if given.
    
    * etc/NEWS: Announce change in shr behavior.
    
    * test/data/shr/ol.html:
    * test/data/shr/ol.txt: New test data files.
---
 etc/NEWS              |  2 ++
 lisp/net/shr.el       |  9 ++++++++-
 test/data/shr/ol.html | 29 +++++++++++++++++++++++++++++
 test/data/shr/ol.txt  | 19 +++++++++++++++++++
 4 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 253da49..30c42fa 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -698,6 +698,8 @@ has been executed.
 If set, shr will not render tags with attribute 'aria-hidden="true"'.
 This attribute is meant to tell screen readers to ignore a tag.
 
+*** 'shr-tag-ol' now respects the ordered list 'start' attribute.
+
 ** Htmlfontify
 
 *** The functions 'hfy-color', 'hfy-color-vals' and
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 94d68fa..2f628e1 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1755,7 +1755,14 @@ The preference is a float determined from 
`shr-prefer-media-type'."
 
 (defun shr-tag-ol (dom)
   (shr-ensure-paragraph)
-  (let ((shr-list-mode 1))
+  (let* ((attrs (dom-attributes dom))
+         (start-attr (alist-get 'start attrs))
+         ;; Start at 1 if there is no start attribute
+         ;; or if start can't be parsed as an integer.
+         (start-index (condition-case _
+                          (cl-parse-integer start-attr)
+                        (t 1)))
+         (shr-list-mode start-index))
     (shr-generic dom))
   (shr-ensure-paragraph))
 
diff --git a/test/data/shr/ol.html b/test/data/shr/ol.html
new file mode 100644
index 0000000..f9a15f2
--- /dev/null
+++ b/test/data/shr/ol.html
@@ -0,0 +1,29 @@
+<ol>
+  <li>one</li>
+  <li>two</li>
+  <li>three</li>
+</ol>
+
+<ol start="10">
+  <li>ten</li>
+  <li>eleven</li>
+  <li>twelve</li>
+</ol>
+
+<ol start="0">
+  <li>zero</li>
+  <li>one</li>
+  <li>two</li>
+</ol>
+
+<ol start="-5">
+  <li>minus five</li>
+  <li>minus four</li>
+  <li>minus three</li>
+</ol>
+
+<ol start="notanumber">
+  <li>one</li>
+  <li>two</li>
+  <li>three</li>
+</ol>
diff --git a/test/data/shr/ol.txt b/test/data/shr/ol.txt
new file mode 100644
index 0000000..0d46e2a
--- /dev/null
+++ b/test/data/shr/ol.txt
@@ -0,0 +1,19 @@
+1 one
+2 two
+3 three
+
+10 ten
+11 eleven
+12 twelve
+
+0 zero
+1 one
+2 two
+
+-5 minus five
+-4 minus four
+-3 minus three
+
+1 one
+2 two
+3 three



reply via email to

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