From: Nicholas Drozd Date: Sat, 16 Feb 2019 22:37:52 +0000 (-0600) Subject: Handle HTML 'ol' start attribute in shr.el X-Git-Tag: emacs-27.0.90~3561 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8282c34f0f2f4ad2c4956fc595518da64a7bef1f;p=emacs.git 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
    if given. * etc/NEWS: Announce change in shr behavior. * test/data/shr/ol.html: * test/data/shr/ol.txt: New test data files. --- diff --git a/etc/NEWS b/etc/NEWS index 253da499899..30c42fa5302 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 94d68faf2a8..2f628e1caa2 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 00000000000..f9a15f26409 --- /dev/null +++ b/test/data/shr/ol.html @@ -0,0 +1,29 @@ +
      +
    1. one
    2. +
    3. two
    4. +
    5. three
    6. +
    + +
      +
    1. ten
    2. +
    3. eleven
    4. +
    5. twelve
    6. +
    + +
      +
    1. zero
    2. +
    3. one
    4. +
    5. two
    6. +
    + +
      +
    1. minus five
    2. +
    3. minus four
    4. +
    5. minus three
    6. +
    + +
      +
    1. one
    2. +
    3. two
    4. +
    5. three
    6. +
    diff --git a/test/data/shr/ol.txt b/test/data/shr/ol.txt new file mode 100644 index 00000000000..0d46e2a8ddb --- /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