all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: raman@google.com
To: emacs-devel@gnu.org
Subject: eww: Feature request: Dont hard-wire shr-external-rendering-functions
Date: Mon, 18 May 2015 08:45:52 -0700	[thread overview]
Message-ID: <21850.2352.916316.846855@gargle.gargle.HOWL> (raw)

I have a feature request motivated by the need to "tag" portions of
the EWW rendered buffer with the tag-name of the sub-tree that
produced the rendering; this helps me then implement structured
navigation of the EWW buffer for Emacspeak.
I've achieved this for header tags etc via an advice on the relevant shr-tag-<tagname> functions.



At present the <article> element  is handled by shr-generic which is a defsubst -- so advice wont work.
 I implemented byself a simple emacspeak-eww-tag-article that does:
(defun emacspeak-eww-tag-article (dom)
  "Tag article, then render."
  (let ((start (point)))
    (shr-generic dom)
        (put-text-property start (point) 'article 'eww-tag)))

But at present, I have no way of telling EWW to add this to shr-external-rendering-functions -- since that variable is let-bound in eww-display-html --- I could probably still get away with advicing shr-insert-document -- but I'd   prefer a simpler solution:-)

Possibilities --

1. Implement shr-tag-article  as above -- essentially rename emacspeak-eww-tag-article to shr-tag-article  -- and update the other shr functions in the recursive descent walk of the HTML tree to set property 'eww-tag -- 

2. If this is overkill for mainstream Emacs users -- then perhaps allow external packages to customize what list of rendering functions eww uses?

For completeness, here is how I generate the advice on the shr-tag-<name> functions to emit the necessary eww-tag properties in the EWW rendered buffer:

(loop
 for  tag in
 '(h1 h2 h3 div                    ; sectioning
      ul ol dl                     ; Lists
      li dt dd p                   ; block-level: bullets, paras
      form blockquote              ; block-level
      a b it em span               ; in-line
      br hr                        ; separators
      th tr table )
 do
 (eval
  ` (defadvice  ,(intern (format "shr-tag-%s" tag)) (around emacspeak pre act comp)
    (let ((start (point)))
      ad-do-it
      (let ((start (if (char-equal (following-char) ?\n)
                       (min (point-max) (1+ start) )start))
            (end (if (> (point) start) (1- (point)) (point))))
        (put-text-property start end
                           (quote ,tag) 'eww-tag)
        (when (memq (quote ,tag) '(h1 h2 h3))
          (put-text-property start end 'h 'eww-tag)))))))

-- 

-- 



             reply	other threads:[~2015-05-18 15:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-18 15:45 raman [this message]
2015-12-24 16:35 ` eww: Feature request: Dont hard-wire shr-external-rendering-functions 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

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

  git send-email \
    --in-reply-to=21850.2352.916316.846855@gargle.gargle.HOWL \
    --to=raman@google.com \
    --cc=emacs-devel@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 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.