From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Accessing the communication channel from a link exporter Date: Fri, 02 Sep 2016 12:33:30 -0400 Message-ID: References: <87inuf1sn8.fsf@saiph.selenimh> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bfrPP-0006XP-1H for emacs-orgmode@gnu.org; Fri, 02 Sep 2016 12:33:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bfrPL-0002bS-RI for emacs-orgmode@gnu.org; Fri, 02 Sep 2016 12:33:39 -0400 Received: from mail-qk0-x230.google.com ([2607:f8b0:400d:c09::230]:34652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bfrPL-0002Yn-LR for emacs-orgmode@gnu.org; Fri, 02 Sep 2016 12:33:35 -0400 Received: by mail-qk0-x230.google.com with SMTP id t7so124617929qkh.1 for ; Fri, 02 Sep 2016 09:33:34 -0700 (PDT) In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Arun Isaac Cc: org-mode-email then the preprocessing hook sounds better. You can just replace the links with generated html, and then export the buffer. For example, here is a function that goes through an org file and replaces links that are file times with image or urls, and copies the file contents to a media-directory. (defun bf-process-links (backend) "Modify links to change paths and copy files to `media-dir'. Argument BACKEND the export backend." (org-mode) (let* ((links (nreverse (org-element-map (org-element-parse-buffer) 'link #'identity)))) (loop for link in links do (let* ((type (org-element-property :type link)) (path (org-element-property :path link)) (beg (org-element-property :begin link)) (end (org-element-property :end link)) (fname (car (last (split-string path "/"))))) (cond ((string= type "file") (copy-file path (concat bf-media-directory fname) t) (setf (buffer-substring beg end) (if (string-match "png\\|svg" (or (file-name-extension (org-element-property :path link)) "")) (format "@@html:@@ " bf-media-url-base fname) (format "@@html:%s@@ " bf-media-url-base fname fname))))))))) This function just wraps an export with a temporary definition of the before processing hook, which runs the function on a copy of the org-buffer you are creating. (defun bf-get-HTML () "Return the body html of the headline at point." (let ((org-export-before-processing-hook '(bf-process-links)) (async nil) (subtreep t) (visible-only nil) (body-only t) (ext-plist '()) ;; (bf-link-counter 0) ;; (url-list (bf-get-link-urls)) (html)) (org-html-export-as-html async subtreep visible-only body-only ext-plist) ;; now get the output into the org output (switch-to-buffer "*Org HTML Export*") (end-of-buffer) (setq html (buffer-string)) (kill-buffer "*Org HTML Export*") html)) No doubt you could make more complicated ;) Arun Isaac writes: >> I think this is the kind of thing you can use a filter for > > But, it gets more complicated than that. I have XMP metadata (license, > caption, etc.) stored in the image files as well. And, in order to > export that, I need the path to the source image file. So, my image link > exporter needs the :base-directory to find the source image file. If I > try to get the XMP metadata from the published image file, then I > introduce a race condition with the export of the org file becoming > dependent on the image file already being published. > > Perhaps, filters could be useful. I need to think about it. So far, I > have generally stayed away from filters because they can only get the > HTML as text, and have to use some kind of regex to operate on it. HTML > is structured data, and it would have been good if it was available in > some kind of S-form tree structure. It would have saved me the trouble > of parsing the HTML, and I could have used a library like xmlgen to > generate it. > > Regards, > Arun Isaac -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu