emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: custom link export and ox-md
Date: Mon, 24 Feb 2014 00:00:29 -0500	[thread overview]
Message-ID: <87ob1xgl5e.fsf@gmail.com> (raw)
In-Reply-To: 530AAA84.3000402@gmail.com

John Peloquin <john.peloquin@gmail.com> writes:

> Greetings,
>
> I'm trying to define a custom link in org mode with custom export
> formatting, but I get unexpected results when exporting to markdown.
>
>
> Minimal example:
>
> `minimal-init.el`
>
> (add-to-list 'load-path "~/.emacs.d/elpa/org-20140217")
> (require 'org)
> (add-to-list 'org-export-backends "md")
>
> (org-add-link-type
>  "cite" nil
>  (lambda (path desc format)
>    (format "[@%s]" path)))
>
>
> `minimal.org`
>
> Some text [[cite:citekey]].
>
>
> When I export `minimal.org` to markdown using C-c C-e m M, I get:
>
> Some text <citekey>.
>
>
> Whereas I expected:
>
> Some text [@citekey].
>
>
> I tried this with a clean emacs configuration (`emacs -Q -l 
> minimal-init.el`).  `org-version` returns 8.2.5h, which as far as I
> know is the latest version.  `emacs-version` is 24.3.1.
>
> I do get the expected export result if I export to latex or html, so
> the link export definition in init.el does work.  Am I doing something
> wrong? 

No.

> Is this a bug in ox-md?
>
Yes. There is no provision for handling user-defined link types. Try the
following patch:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index b8316dd..fa64f2d 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -340,6 +340,10 @@ a communication channel."
 		   (when number
 		     (if (atom number) (number-to-string number)
 		       (mapconcat 'number-to-string number "."))))))))
+	  ;; Link type is handled by a special function.
+	  ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
+	   (funcall protocol (org-element-property :path link) contents 'md))
+
 	  (t (let* ((raw-path (org-element-property :path link))
 		    (path
 		     (cond
--8<---------------cut here---------------end--------------->8---


Lightly tested with your reproducer - thanks for providing one!

-- 
Nick

  reply	other threads:[~2014-02-24  5:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-24  2:12 custom link export and ox-md John Peloquin
2014-02-24  5:00 ` Nick Dokos [this message]
2014-02-24 19:37   ` Nick Dokos
2014-02-25 17:20     ` Nicolas Goaziou
2014-03-21  8:15       ` Bastien

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=87ob1xgl5e.fsf@gmail.com \
    --to=ndokos@gmail.com \
    --cc=emacs-orgmode@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 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).