GNU bug report logs - #19462
shr: use wrap-prefix when possible, instead of filling the text

Previous Next

Package: emacs;

Reported by: Ivan Shmakov <ivan <at> siamics.net>

Date: Mon, 29 Dec 2014 07:56:02 UTC

Severity: wishlist

Tags: patch

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 19462 in the body.
You can then email your comments to 19462 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to emacs-devel <at> gnu.org, bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Mon, 29 Dec 2014 07:56:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ivan Shmakov <ivan <at> siamics.net>:
New bug report received and forwarded. Copy sent to emacs-devel <at> gnu.org, bug-gnu-emacs <at> gnu.org. (Mon, 29 Dec 2014 07:56:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ivan Shmakov <ivan <at> siamics.net>
To: submit <at> debbugs.gnu.org
Subject: shr: use wrap-prefix when possible, instead of filling the text 
Date: Mon, 29 Dec 2014 07:55:41 +0000
[Message part 1 (text/plain, inline)]
Package:  emacs
Severity: wishlist
X-Debbugs-Cc: emacs-devel <at> gnu.org

>>>>> Eli Zaretskii <eliz <at> gnu.org> writes:
>>>>> From: Lars Ingebrigtsen  Date: Mon, 29 Dec 2014 00:04:38 +0100

 >> (Yes, Emacs can display proportional fonts and fonts of different
 >> sizes, but until you can fold (etc) proportional text (and text with
 >> a mixture of font sizes) in a pretty manner, that's more of a toy
 >> than anything else.)

 > What's non-pretty with how we do this now?  What features are
 > missing?

	The only feature that I’m aware to be missing is the actual
	support for Emacs native text wrapping (as in: the word-wrap
	variable and wrap-prefix text property) in SHR.

	Please thus consider the patch MIMEd.

	* lisp/net/shr.el (shr-force-fill): New variable to disable this
	feature if needed.
	(shr-internal-width): Defer initialization until...
	(shr-insert-document): ... here; set to nil if neither
	shr-force-fill nor shr-width are non-nil.
	(shr-fold-text, shr-tag-table-1): Likewise.
	(shr-insert): Use insert-and-inherit; do not fill if
	shr-internal-width is nil.
	(shr-setup-wrap): New function.
	(shr-indent, shr-tag-blockquote, shr-tag-dd, shr-tag-li):
	Call shr-setup-wrap.
	(shr-tag-hr): Use a constant if shr-internal-width is nil.

	A test case is also MIMEd.  The buffer it produces shows the
	text being dynamically filled as the window width changes
	(as in: C-x 3, for instance.)

	The table rendering is not changed in any way.

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A
[Message part 2 (text/diff, inline)]
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 26bb292..e634a5a 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -128,13 +128,16 @@
 (defvar shr-inhibit-images nil
   "If non-nil, inhibit loading images.")
 
+(defvar shr-force-fill nil
+  "If non-nil, fill text even in the cases Emacs can wrap it by itself.")
+
 ;;; Internal variables.
 
 (defvar shr-folding-mode nil)
 (defvar shr-state nil)
 (defvar shr-start nil)
 (defvar shr-indentation 0)
-(defvar shr-internal-width (or shr-width (1- (window-width))))
+(defvar shr-internal-width nil)		; set in shr-insert-document
 (defvar shr-list-mode nil)
 (defvar shr-content-cache nil)
 (defvar shr-kinsoku-shorten nil)
@@ -206,7 +209,8 @@ defun shr-insert-document (dom)
 	(shr-base nil)
 	(shr-depth 0)
 	(shr-warning nil)
-	(shr-internal-width (or shr-width (1- (window-width)))))
+	(shr-internal-width
+	 (or shr-width (and shr-force-fill (1- (window-width))))))
     (shr-descend dom)
     (shr-remove-trailing-whitespace start (point))
     (when shr-warning
@@ -420,7 +424,8 @@ defun shr-fold-text (text)
       (let ((shr-indentation 0)
 	    (shr-state nil)
 	    (shr-start nil)
-	    (shr-internal-width (window-width)))
+	    (shr-internal-width (and shr-force-fill
+				     (1- (window-width)))))
 	(shr-insert text)
 	(buffer-string)))))
 
@@ -454,12 +459,14 @@ defun shr-insert (text)
     (setq shr-state nil))
   (cond
    ((eq shr-folding-mode 'none)
-    (insert text))
+    (insert-and-inherit text))
    (t
+    ;; We generally use insert-and-inherit below so to inherit the
+    ;; wrap-prefix property, if any.  See shr-setup-wrap.
     (when (and (string-match "\\`[ \t\n ]" text)
 	       (not (bolp))
 	       (not (eq (char-after (1- (point))) ? )))
-      (insert " "))
+      (insert-and-inherit " "))
     (dolist (elem (split-string text "[ \f\t\n\r\v ]+" t))
       (when (and (bolp)
 		 (> shr-indentation 0))
@@ -482,17 +489,18 @@ defun shr-insert (text)
       ;; starts.
       (unless shr-start
 	(setq shr-start (point)))
-      (insert elem)
+      (insert-and-inherit elem)
       (setq shr-state nil)
       (let (found)
-	(while (and (> (current-column) shr-internal-width)
+	(while (and shr-internal-width	; Use Emacs native wrapping if nil.
+		    (> (current-column) shr-internal-width)
 		    (> shr-internal-width 0)
 		    (progn
 		      (setq found (shr-find-fill-point))
 		      (not (eolp))))
 	  (when (eq (preceding-char) ? )
 	    (delete-char -1))
-	  (insert "\n")
+	  (insert-and-inherit "\n")
 	  (unless found
 	    ;; No space is needed at the beginning of a line.
 	    (when (eq (following-char) ? )
@@ -500,11 +508,12 @@ defun shr-insert (text)
 	  (when (> shr-indentation 0)
 	    (shr-indent))
 	  (end-of-line))
-	(if (<= (current-column) shr-internal-width)
-	    (insert " ")
+	(if (or (not shr-internal-width)
+		(<= (current-column) shr-internal-width))
+	    (insert-and-inherit " ")
 	  ;; In case we couldn't get a valid break point (because of a
 	  ;; word that's longer than `shr-internal-width'), just break anyway.
-	  (insert "\n")
+	  (insert-and-inherit "\n")
 	  (when (> shr-indentation 0)
 	    (shr-indent)))))
     (unless (string-match "[ \t\r\n ]\\'" text)
@@ -663,7 +672,17 @@
 
 (defun shr-indent ()
   (when (> shr-indentation 0)
-    (insert (make-string shr-indentation ? ))))
+    (insert (make-string shr-indentation ? ))
+    (shr-setup-wrap)))
+
+(defun shr-setup-wrap ()
+  (when (> shr-indentation 0)
+    ;; The wrap-prefix property is sticky; abuse that here.  We use
+    ;; this after at least shr-indent (or within it), so we may safely
+    ;; assume that there is at least one character before the point.
+    (put-text-property (+ -1 (point)) (point)
+		       'wrap-prefix
+		       `(space :align-to ,shr-indentation))))
 
 (defun shr-fontize-dom (dom &rest types)
   (let (shr-start)
@@ -1309,6 +1334,7 @@ defun shr-tag-blockquote (dom)
   (shr-ensure-paragraph)
   (shr-indent)
   (let ((shr-indentation (+ shr-indentation 4)))
+    (shr-setup-wrap)
     (shr-generic dom))
   (shr-ensure-paragraph))
 
@@ -1325,6 +1351,7 @@
 (defun shr-tag-dd (dom)
   (shr-ensure-newline)
   (let ((shr-indentation (+ shr-indentation 4)))
+    (shr-setup-wrap)
     (shr-generic dom)))
 
 (defun shr-tag-ul (dom)
@@ -1350,6 +1377,7 @@ defun shr-tag-li (dom)
 	    shr-bullet))
 	 (shr-indentation (+ shr-indentation (length bullet))))
     (insert bullet)
+    (shr-setup-wrap)
     (shr-generic dom)))
 
 (defun shr-tag-br (dom)
@@ -1386,7 +1414,8 @@
 
 (defun shr-tag-hr (_dom)
   (shr-ensure-newline)
-  (insert (make-string shr-internal-width shr-hr-line) "\n"))
+  (insert (make-string (or shr-internal-width 31) ; FIXME: magic
+		       shr-hr-line) "\n"))
 
 (defun shr-tag-title (dom)
   (shr-heading dom 'bold 'underline))
@@ -1414,6 +1443,7 @@
 (defun shr-tag-table-1 (dom)
   (setq dom (or (dom-child-by-tag dom 'tbody) dom))
   (let* ((shr-inhibit-images t)
+	 (shr-internal-width (or shr-internal-width (1- (window-width))))
 	 (shr-table-depth (1+ shr-table-depth))
 	 (shr-kinsoku-shorten t)
 	 ;; Find all suggested widths.
[Message part 3 (text/emacs-lisp, inline)]
(with-current-buffer (generate-new-buffer "*shr*")
  (setq-local shr-width nil)
  (setq-local word-wrap t)
  (setq-local truncate-partial-width-windows nil)
  (shr-insert-document
   '(base
     ((href . "https://example.com/"))
     (html
      nil
      (head nil (title nil "Lorem ipsum"))
      (body
       nil
       (hr nil)
       (ol nil
	   (li ((lang . "la"))
	       "Lorem ipsum dolor sit amet, consectetur adipisicing"
	       " elit, sed do eiusmod tempor incididunt ut labore et"
	       " dolore magna aliqua.  Ut enim ad minim veniam, quis"
	       " nostrud exercitation ullamco laboris nisi ut"
	       " aliquip ex ea commodo consequat.  Duis aute irure"
	       " dolor in reprehenderit in voluptate velit esse"
	       " cillum dolore eu fugiat nulla pariatur.  Excepteur"
	       " sint occaecat cupidatat non proident, sunt in culpa"
	       " qui officia deserunt mollit anim id est laborum."))))))
  (pop-to-buffer (current-buffer)))

Added tag(s) patch. Request was from Ivan Shmakov <ivan <at> siamics.net> to control <at> debbugs.gnu.org. (Mon, 29 Dec 2014 09:02:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Mon, 29 Dec 2014 09:56:02 GMT) Full text and rfc822 format available.

Message #10 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Ivan Shmakov <ivan <at> siamics.net>
To: 19462 <at> debbugs.gnu.org
Cc: emacs-devel <at> gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible,
 instead of filling the text 
Date: Mon, 29 Dec 2014 09:55:15 +0000
[Message part 1 (text/plain, inline)]
	As it seems, the initial version of the patch didn’t play well
	with other essential shr.el features (as in: hyperlinks.)

	Please thus consider the revised patch MIMEd.

	* lisp/net/shr.el (shr-force-fill): New variable to disable this
	feature if needed.
	(shr-internal-width): Defer initialization until...
	(shr-insert-document): ... here; set to nil if neither
	shr-force-fill nor shr-width are non-nil.
	(shr-fold-text, shr-tag-table-1): Likewise.
	(shr-insert): Do not fill if shr-internal-width is nil.
	(shr-setup-wrap-1, shr-setup-wrap): New function.
	(shr-tag-blockquote, shr-tag-dd, shr-tag-li):
	Call shr-setup-wrap.
	(shr-tag-hr): Use a constant if shr-internal-width is nil.

	The other so far unresolved issue with this approach is that the
	tables and <pre /> elements may actually require truncate-lines.
	Unfortunately, I know of no way to allow for word-wrapped and
	truncated lines to exist in the same buffer; I guess we may need
	either a truncate-lines or word-wrap property (or both) to
	override the buffer-local variables in this case.

	Similarly to wrap-prefix, we may also use line-prefix in place
	of shr-indent.  But that may not be a good idea if quoting
	text/html messages in text/plain replies, for instance.

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A
[Message part 2 (text/diff, inline)]
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -128,13 +128,16 @@
 (defvar shr-inhibit-images nil
   "If non-nil, inhibit loading images.")
 
+(defvar shr-force-fill nil
+  "If non-nil, fill text even in the cases Emacs can wrap it by itself.")
+
 ;;; Internal variables.
 
 (defvar shr-folding-mode nil)
 (defvar shr-state nil)
 (defvar shr-start nil)
 (defvar shr-indentation 0)
-(defvar shr-internal-width (or shr-width (1- (window-width))))
+(defvar shr-internal-width nil)		; set in shr-insert-document
 (defvar shr-list-mode nil)
 (defvar shr-content-cache nil)
 (defvar shr-kinsoku-shorten nil)
@@ -206,7 +209,8 @@ defun shr-insert-document (dom)
 	(shr-base nil)
 	(shr-depth 0)
 	(shr-warning nil)
-	(shr-internal-width (or shr-width (1- (window-width)))))
+	(shr-internal-width
+	 (or shr-width (and shr-force-fill (1- (window-width))))))
     (shr-descend dom)
     (shr-remove-trailing-whitespace start (point))
     (when shr-warning
@@ -420,7 +424,8 @@ defun shr-fold-text (text)
       (let ((shr-indentation 0)
 	    (shr-state nil)
 	    (shr-start nil)
-	    (shr-internal-width (window-width)))
+	    (shr-internal-width (and shr-force-fill
+				     (1- (window-width)))))
 	(shr-insert text)
 	(buffer-string)))))
 
@@ -485,7 +490,8 @@ defun shr-insert (text)
       (insert elem)
       (setq shr-state nil)
       (let (found)
-	(while (and (> (current-column) shr-internal-width)
+	(while (and shr-internal-width	; Use Emacs native wrapping if nil.
+		    (> (current-column) shr-internal-width)
 		    (> shr-internal-width 0)
 		    (progn
 		      (setq found (shr-find-fill-point))
@@ -500,7 +506,8 @@ defun shr-insert (text)
 	  (when (> shr-indentation 0)
 	    (shr-indent))
 	  (end-of-line))
-	(if (<= (current-column) shr-internal-width)
+	(if (or (not shr-internal-width)
+		(<= (current-column) shr-internal-width))
 	    (insert " ")
 	  ;; In case we couldn't get a valid break point (because of a
 	  ;; word that's longer than `shr-internal-width'), just break anyway.
@@ -665,6 +672,23 @@
   (when (> shr-indentation 0)
     (insert (make-string shr-indentation ? ))))
 
+(defun shr-setup-wrap-1 (from to pval)
+  (put-text-property from to 'wrap-prefix pval))
+
+(defun shr-setup-wrap (from to)
+  (let ((prev from)
+	(pos  (next-property-change from nil to))
+	(pval (and (> shr-indentation 0)
+		   `(space :align-to ,shr-indentation))))
+    (while (and pos (> pos prev))
+      (unless (get-text-property prev 'wrap-prefix)
+	(shr-setup-wrap-1 prev pos pval))
+      (setq prev pos
+	    pos  (next-property-change pos nil to)))
+    (unless (or (<= to prev)
+		(get-text-property prev 'wrap-prefix))
+	(shr-setup-wrap-1 prev to pval))))
+
 (defun shr-fontize-dom (dom &rest types)
   (let (shr-start)
     (shr-generic dom)
@@ -1308,8 +1338,10 @@
 (defun shr-tag-blockquote (dom)
   (shr-ensure-paragraph)
   (shr-indent)
-  (let ((shr-indentation (+ shr-indentation 4)))
-    (shr-generic dom))
+  (let ((from (point))
+	(shr-indentation (+ shr-indentation 4)))
+    (shr-generic dom)
+    (shr-setup-wrap from (point)))
   (shr-ensure-paragraph))
 
 (defun shr-tag-dl (dom)
@@ -1324,8 +1356,10 @@
 
 (defun shr-tag-dd (dom)
   (shr-ensure-newline)
-  (let ((shr-indentation (+ shr-indentation 4)))
-    (shr-generic dom)))
+  (let ((from (point))
+	(shr-indentation (+ shr-indentation 4)))
+    (shr-generic dom)
+    (shr-setup-wrap from (point))))
 
 (defun shr-tag-ul (dom)
   (shr-ensure-paragraph)
@@ -1348,9 +1382,11 @@ defun shr-tag-li (dom)
 		  (format "%d " shr-list-mode)
 		(setq shr-list-mode (1+ shr-list-mode)))
 	    shr-bullet))
+	 (from (point))
 	 (shr-indentation (+ shr-indentation (length bullet))))
     (insert bullet)
-    (shr-generic dom)))
+    (shr-generic dom)
+    (shr-setup-wrap from (point))))
 
 (defun shr-tag-br (dom)
   (when (and (not (bobp))
@@ -1386,7 +1422,8 @@
 
 (defun shr-tag-hr (_dom)
   (shr-ensure-newline)
-  (insert (make-string shr-internal-width shr-hr-line) "\n"))
+  (insert (make-string (or shr-internal-width 31) ; FIXME: magic
+		       shr-hr-line) "\n"))
 
 (defun shr-tag-title (dom)
   (shr-heading dom 'bold 'underline))
@@ -1414,6 +1451,7 @@
 (defun shr-tag-table-1 (dom)
   (setq dom (or (dom-child-by-tag dom 'tbody) dom))
   (let* ((shr-inhibit-images t)
+	 (shr-internal-width (or shr-internal-width (1- (window-width))))
 	 (shr-table-depth (1+ shr-table-depth))
 	 (shr-kinsoku-shorten t)
 	 ;; Find all suggested widths.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Fri, 25 Dec 2015 17:36:02 GMT) Full text and rfc822 format available.

Message #13 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Ivan Shmakov <ivan <at> siamics.net>
Cc: 19462 <at> debbugs.gnu.org, emacs-devel <at> gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible,
 instead of filling the text
Date: Fri, 25 Dec 2015 18:34:46 +0100
Ivan Shmakov <ivan <at> siamics.net> writes:

>  >> (Yes, Emacs can display proportional fonts and fonts of different
>  >> sizes, but until you can fold (etc) proportional text (and text with
>  >> a mixture of font sizes) in a pretty manner, that's more of a toy
>  >> than anything else.)
>
>  > What's non-pretty with how we do this now?  What features are
>  > missing?
>
> 	The only feature that I’m aware to be missing is the actual
> 	support for Emacs native text wrapping (as in: the word-wrap
> 	variable and wrap-prefix text property) in SHR.
>
> 	Please thus consider the patch MIMEd.

I think this was superseded by the shr proportional font rewrite, so I'm
closing the bug.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 19462 <at> debbugs.gnu.org and Ivan Shmakov <ivan <at> siamics.net> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 25 Dec 2015 17:36:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Fri, 25 Dec 2015 22:52:01 GMT) Full text and rfc822 format available.

Message #18 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Clément Pit--Claudel <clement.pit <at> gmail.com>
Cc: 19462 <at> debbugs.gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible,
 instead of filling the text
Date: Fri, 25 Dec 2015 23:51:02 +0100
Clément Pit--Claudel <clement.pit <at> gmail.com> writes:

> I do not know how to do this, but it sounds like a convenient
> solution! How does one tell shr to apply a particular font to its
> target (all that I know of is `shr-target-id', which seems to insert a
> '*')?

Look at `shr-tag-h1', for instance, and create whatever similar version
of that you want by overriding with `shr-external-rendering-functions'.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Sat, 26 Dec 2015 09:14:01 GMT) Full text and rfc822 format available.

Message #21 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Ivan Shmakov <ivan <at> siamics.net>
To: 19462 <at> debbugs.gnu.org, emacs-devel <at> gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible,
 instead of filling the text 
Date: Sat, 26 Dec 2015 09:13:02 +0000
>>>>> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>>>>> Ivan Shmakov <ivan <at> siamics.net> writes:

[…]

 >> The only feature that I’m aware to be missing is the actual support
 >> for Emacs native text wrapping (as in: the word-wrap variable and
 >> wrap-prefix text property) in SHR.

 >> Please thus consider the patch MIMEd.

 > I think this was superseded by the shr proportional font rewrite, so
 > I'm closing the bug.

	I’ve stopped using the SHR version that comes with Emacs this
	May, so I don’t think I care much about that any longer.

	I have several items in my wishlist regarding rendering HTML in
	Emacs buffers, but I guess they will warrant writing the code
	anew, presumably to be released under a different name, so that
	it can be installed alongside SHR.

	(Not that I currently have much spare time to dedicate to that.)

-- 
FSF associate member #7257  http://am-1.org/~ivan/      … 3013 B6A0 230E 334A




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Sat, 26 Dec 2015 18:31:03 GMT) Full text and rfc822 format available.

Message #24 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit--Claudel <clement.pit <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 19462 <at> debbugs.gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible, instead of filling
 the text
Date: Sat, 26 Dec 2015 17:53:39 +0100
[Message part 1 (text/plain, inline)]
On 12/25/2015 11:51 PM, Lars Ingebrigtsen wrote:
> Clément Pit--Claudel <clement.pit <at> gmail.com> writes:
> 
>> I do not know how to do this, but it sounds like a convenient
>> solution! How does one tell shr to apply a particular font to its
>> target (all that I know of is `shr-target-id', which seems to insert a
>> '*')?
> 
> Look at `shr-tag-h1', for instance, and create whatever similar version
> of that you want by overriding with `shr-external-rendering-functions'.

That sounds like a great idea, actually. And I guess I can get the id of the current element to check it against the target id using (equal (dom-attr dom 'id) TARGET-ID).

I'll try that!

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Sun, 27 Dec 2015 03:37:01 GMT) Full text and rfc822 format available.

Message #27 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit--Claudel <clement.pit <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 19462 <at> debbugs.gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible, instead of filling
 the text
Date: Sun, 27 Dec 2015 04:36:40 +0100
[Message part 1 (text/plain, inline)]
On 12/26/2015 05:53 PM, Clément Pit--Claudel wrote:
> On 12/25/2015 11:51 PM, Lars Ingebrigtsen wrote:
>> Clément Pit--Claudel <clement.pit <at> gmail.com> writes:
>>
>>> I do not know how to do this, but it sounds like a convenient
>>> solution! How does one tell shr to apply a particular font to its
>>> target (all that I know of is `shr-target-id', which seems to insert a
>>> '*')?
>>
>> Look at `shr-tag-h1', for instance, and create whatever similar version
>> of that you want by overriding with `shr-external-rendering-functions'.
> 
> That sounds like a great idea, actually. And I guess I can get the id of the current element to check it against the target id using (equal (dom-attr dom 'id) TARGET-ID).
> 
> I'll try that!

I just tried this (capturing the id that I was interested in in a closure instead of putting it in shr-target-id), but shr-descend only works with globally defined functions; is there a reason for that? It's due to the following bit: 

	(if (fboundp function)
	    (funcall function dom)
	  (shr-generic dom))

Clément.

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Sun, 27 Dec 2015 04:20:02 GMT) Full text and rfc822 format available.

Message #30 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit--Claudel <clement.pit <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 19462 <at> debbugs.gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible, instead of filling
 the text
Date: Sun, 27 Dec 2015 05:19:35 +0100
[Message part 1 (text/plain, inline)]
On 12/27/2015 04:36 AM, Clément Pit--Claudel wrote:
> On 12/26/2015 05:53 PM, Clément Pit--Claudel wrote:
>> On 12/25/2015 11:51 PM, Lars Ingebrigtsen wrote:
>>> Clément Pit--Claudel <clement.pit <at> gmail.com> writes:
>>>
>>>> I do not know how to do this, but it sounds like a convenient
>>>> solution! How does one tell shr to apply a particular font to its
>>>> target (all that I know of is `shr-target-id', which seems to insert a
>>>> '*')?
>>>
>>> Look at `shr-tag-h1', for instance, and create whatever similar version
>>> of that you want by overriding with `shr-external-rendering-functions'.
>>
>> That sounds like a great idea, actually. And I guess I can get the id of the current element to check it against the target id using (equal (dom-attr dom 'id) TARGET-ID).
>>
>> I'll try that!

I looked into this more, but I don't think it will work. I want to highlight the context of the element that contains the target id, so if lines are not broken up then highlighting the full line works well. If they are, on the other hand, then I can't tell how much surrounding text to highlight.

Cheers,
Clément.

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Sun, 27 Dec 2015 06:20:02 GMT) Full text and rfc822 format available.

Message #33 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Clément Pit--Claudel <clement.pit <at> gmail.com>
Cc: 19462 <at> debbugs.gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible,
 instead of filling the text
Date: Sun, 27 Dec 2015 07:19:24 +0100
Clément Pit--Claudel <clement.pit <at> gmail.com> writes:

> I just tried this (capturing the id that I was interested in in a
> closure instead of putting it in shr-target-id), but shr-descend only
> works with globally defined functions; is there a reason for that?
> It's due to the following bit:
>
> 	(if (fboundp function)
> 	    (funcall function dom)
> 	  (shr-generic dom))

I've now fixed this in the Emacs trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Sun, 27 Dec 2015 06:24:01 GMT) Full text and rfc822 format available.

Message #36 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Clément Pit--Claudel <clement.pit <at> gmail.com>
Cc: 19462 <at> debbugs.gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible,
 instead of filling the text
Date: Sun, 27 Dec 2015 07:22:55 +0100
Clément Pit--Claudel <clement.pit <at> gmail.com> writes:

> I looked into this more, but I don't think it will work. I want to
> highlight the context of the element that contains the target id, so
> if lines are not broken up then highlighting the full line works
> well. If they are, on the other hand, then I can't tell how much
> surrounding text to highlight.

I'm not sure what you mean by "context".  But you can look "down" into
the DOM and see if your id is in an element there.  Or you can transform
the HTML, or transform the DOM, to wrap the elements you want to
highlight.

For instance, you can loop over all elements that have ids that match
with `dom-by-id', and you can alter the DOM to insert, say, h1 elements
around those that you want to have highlit.

Etc.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19462; Package emacs. (Sun, 27 Dec 2015 11:18:02 GMT) Full text and rfc822 format available.

Message #39 received at 19462 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit--Claudel <clement.pit <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 19462 <at> debbugs.gnu.org
Subject: Re: bug#19462: shr: use wrap-prefix when possible, instead of filling
 the text
Date: Sun, 27 Dec 2015 12:16:48 +0100
[Message part 1 (text/plain, inline)]
On 12/27/2015 07:22 AM, Lars Ingebrigtsen wrote:
> Clément Pit--Claudel <clement.pit <at> gmail.com> writes:
> 
>> I looked into this more, but I don't think it will work. I want to
>> highlight the context of the element that contains the target id, so
>> if lines are not broken up then highlighting the full line works
>> well. If they are, on the other hand, then I can't tell how much
>> surrounding text to highlight.
> 
> I'm not sure what you mean by "context".  But you can look "down" into
> the DOM and see if your id is in an element there.  Or you can transform
> the HTML, or transform the DOM, to wrap the elements you want to
> highlight.
> 
> For instance, you can loop over all elements that have ids that match
> with `dom-by-id', and you can alter the DOM to insert, say, h1 elements
> around those that you want to have highlit.

Thanks for the suggestions. It's not always obvious what element I want to highlight, though, beyond "everything that ends up on the same line. It may be that the thing I want to draw the attention of the user to is in a paragraph; in that case, I highlight the full paragrahp. Or it may be in a title; in that case, I highlight the full title. Or it may be part of a list; in that case I only highlight the item that contains it.

When the text that shr inserts isn't wrapped, I just need to highlight the line that contains that text after rendering is complete. When it is wrapped, however, it becomes unclear what exactly to highlight.

Clément.

[signature.asc (application/pgp-signature, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 24 Jan 2016 12:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 287 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.