emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Accessing the communication channel from a link exporter
@ 2016-08-31 11:57 Arun Isaac
  2016-09-01 16:39 ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Arun Isaac @ 2016-08-31 11:57 UTC (permalink / raw)
  To: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 378 bytes --]


When adding a new hyperlink type using `org-add-link-type', how do I
access the info communication channel from the link exporter function?

Not being able to access the communication channel limits what I can do
with `org-add-link-type', and I end up creating a derived backend with
my own link transcoder function. Is that the recommended way to do it?

Regards,
Arun Isaac.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accessing the communication channel from a link exporter
  2016-08-31 11:57 Accessing the communication channel from a link exporter Arun Isaac
@ 2016-09-01 16:39 ` Nicolas Goaziou
  2016-09-01 18:27   ` Arun Isaac
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2016-09-01 16:39 UTC (permalink / raw)
  To: Arun Isaac; +Cc: org-mode-email

Hello,

Arun Isaac <arunisaac@systemreboot.net> writes:

> When adding a new hyperlink type using `org-add-link-type', how do I
> access the info communication channel from the link exporter function?

You cannot. The :export link parameter is orthogonal to the export
back-end. The latter only kicks in once the former forfeits.

> Not being able to access the communication channel limits what I can do
> with `org-add-link-type', and I end up creating a derived backend with
> my own link transcoder function. Is that the recommended way to do it?

That's the idea, yes. 

Out of curiosity, what kind of link are you using, that is dependant
about context ?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accessing the communication channel from a link exporter
  2016-09-01 16:39 ` Nicolas Goaziou
@ 2016-09-01 18:27   ` Arun Isaac
  2016-09-02 12:30     ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Arun Isaac @ 2016-09-01 18:27 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]


> Out of curiosity, what kind of link are you using, that is dependant
> about context ?

Actually, I don't need the context of the link in the org document. I
need some properties defined in the plist of the component in
org-publish-project-alist. So, I use the info communication channel to
access these properties.

I maintain a few websites with org mode. When I publish an image link
with org, the exported HTML contains the full filesystem path of the
image. The page wouldn't work if I published it on the web. My link type
needs to know the path of the web server's docroot to remove that
component from the full filesystem path. This path is defined in one of
the properties in org-publish-project-alist, and I need the info
communication channel to access it.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accessing the communication channel from a link exporter
  2016-09-01 18:27   ` Arun Isaac
@ 2016-09-02 12:30     ` John Kitchin
  2016-09-02 15:33       ` Arun Isaac
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2016-09-02 12:30 UTC (permalink / raw)
  To: Arun Isaac; +Cc: org-mode-email, Nicolas Goaziou

I think this is the kind of thing you can use a filter for, or a
function in the org-export-before-processing-hook to change the paths
prior to export.

Arun Isaac writes:

>> Out of curiosity, what kind of link are you using, that is dependant
>> about context ?
>
> Actually, I don't need the context of the link in the org document. I
> need some properties defined in the plist of the component in
> org-publish-project-alist. So, I use the info communication channel to
> access these properties.
>
> I maintain a few websites with org mode. When I publish an image link
> with org, the exported HTML contains the full filesystem path of the
> image. The page wouldn't work if I published it on the web. My link type
> needs to know the path of the web server's docroot to remove that
> component from the full filesystem path. This path is defined in one of
> the properties in org-publish-project-alist, and I need the info
> communication channel to access it.


-- 
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accessing the communication channel from a link exporter
  2016-09-02 12:30     ` John Kitchin
@ 2016-09-02 15:33       ` Arun Isaac
  2016-09-02 16:33         ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Arun Isaac @ 2016-09-02 15:33 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 990 bytes --]


> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accessing the communication channel from a link exporter
  2016-09-02 15:33       ` Arun Isaac
@ 2016-09-02 16:33         ` John Kitchin
  2016-09-03 18:35           ` Arun Isaac
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2016-09-02 16:33 UTC (permalink / raw)
  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:<img src=\"%s%s\">@@ "
			 bf-media-url-base fname)
		      (format
		       "@@html:<a href=\"%s%s\">%s</a>@@ "
		       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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accessing the communication channel from a link exporter
  2016-09-02 16:33         ` John Kitchin
@ 2016-09-03 18:35           ` Arun Isaac
  0 siblings, 0 replies; 7+ messages in thread
From: Arun Isaac @ 2016-09-03 18:35 UTC (permalink / raw)
  To: org-mode-email


John Kitchin writes:

> 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.

Thank you. I'll try to adapt this to my use case.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-03 18:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-31 11:57 Accessing the communication channel from a link exporter Arun Isaac
2016-09-01 16:39 ` Nicolas Goaziou
2016-09-01 18:27   ` Arun Isaac
2016-09-02 12:30     ` John Kitchin
2016-09-02 15:33       ` Arun Isaac
2016-09-02 16:33         ` John Kitchin
2016-09-03 18:35           ` Arun Isaac

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).