emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix ox-md remote image links export
@ 2017-08-06  2:43 Jay Kamat
  2017-08-06  7:15 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Jay Kamat @ 2017-08-06  2:43 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi!

I discovered a bug in the ox-md exporter and have created a patch to fix it:

Previously, this image link:
[[https://git-scm.com/images/logo@2x.png]]

would export to:
![img](//git-scm.com/images/logo@2x.png)

which is an invalid markdown image, and won't display properly in
browsers and other places.

A workaround (which I have been using extremely heavily), is:
[[file:https://git-scm.com/images/logo@2x.png]]

which exports to
![img](https://git-scm.com/images/logo@2x.png)

Which is the proper (unbroken) image link.

I have attached a patch which fixes the first example, so it exports
the same link as the workaround (and is no longer broken).

One of my concerns with the attached patch is whether there's a better
way to determine if a link is 'remote'. Maybe I should make a constant
in the file listing 'remote' types and use that everywhere.
I'm also not sure if I broke any other type of image link (but the
simple local case seems to work fine).

My papers are currently being processed, but I thought I would post
this patch early to get feedback, since ideally I would like this bug
to be fixed as soon as possible :). Hopefully they'll be done before
the review is completed.

Let me know if you see anything wrong, and thanks again for hacking org mode :D.

-Jay

[-- Attachment #2: 0001-ox-md.el-Fix-exporting-of-remote-image-links.patch --]
[-- Type: text/x-patch, Size: 1552 bytes --]

From b4768baf2c6ea234c92f24540ed927cf8473e999 Mon Sep 17 00:00:00 2001
From: Jay Kamat <jaygkamat@gmail.com>
Date: Sat, 5 Aug 2017 19:14:44 -0700
Subject: [PATCH] ox-md.el: Fix exporting of remote image links

* lisp/ox-md.el (org-md-link): Check if a link is a remote, and if so,
  use the raw-link property of the link, rather than the path.

A workaround for this bug is to do this:
[[file:http://orgmode.org/img/org-mode-unicorn-logo.png]]

This commit lets the workaround continue working, while the proper method:
[[http://orgmode.org/img/org-mode-unicorn-logo.png]]
is fixed.
---
 lisp/ox-md.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 08e3852823..a4e1d6749b 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -430,8 +430,14 @@ a communication channel."
 	       (format "[%s](#%s)"
 		       description
 		       (org-export-get-reference destination info))))))))
+     ;; Generate a md image link
      ((org-export-inline-image-p link org-html-inline-image-rules)
-      (let ((path (let ((raw-path (org-element-property :path link)))
+       ;; Get the path and caption to insert into the image
+       (let ((path (let ((raw-path
+			   ;; types of links which we just use the raw link
+			   (if (member type '("http" "https" "ftp"))
+			     (org-element-property :raw-link link)
+			     (org-element-property :path link))))
 		    (if (not (file-name-absolute-p raw-path)) raw-path
 		      (expand-file-name raw-path))))
 	    (caption (org-export-data
-- 
2.11.0


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

* Re: [PATCH] Fix ox-md remote image links export
  2017-08-06  2:43 [PATCH] Fix ox-md remote image links export Jay Kamat
@ 2017-08-06  7:15 ` Nicolas Goaziou
  2017-08-06 16:10   ` Jay Kamat
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2017-08-06  7:15 UTC (permalink / raw)
  To: Jay Kamat; +Cc: emacs-orgmode

Hello,

Jay Kamat <jaygkamat@gmail.com> writes:

> I discovered a bug in the ox-md exporter and have created a patch to fix it:
>
> Previously, this image link:
> [[https://git-scm.com/images/logo@2x.png]]
>
> would export to:
> ![img](//git-scm.com/images/logo@2x.png)
>
> which is an invalid markdown image, and won't display properly in
> browsers and other places.
>
> A workaround (which I have been using extremely heavily), is:
> [[file:https://git-scm.com/images/logo@2x.png]]
>
> which exports to
> ![img](https://git-scm.com/images/logo@2x.png)
>
> Which is the proper (unbroken) image link.
>
> I have attached a patch which fixes the first example, so it exports
> the same link as the workaround (and is no longer broken).

Thank you for the report and the patch. I have committed a slightly
different change. Does it solve your issue?

> My papers are currently being processed, but I thought I would post
> this patch early to get feedback, since ideally I would like this bug
> to be fixed as soon as possible :). Hopefully they'll be done before
> the review is completed.

Great! Let me know when the process is done.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] Fix ox-md remote image links export
  2017-08-06  7:15 ` Nicolas Goaziou
@ 2017-08-06 16:10   ` Jay Kamat
  0 siblings, 0 replies; 3+ messages in thread
From: Jay Kamat @ 2017-08-06 16:10 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Hi,

> Thank you for the report and the patch. I have committed a slightly
> different change. Does it solve your issue?

Yup, this commit solves my issues, thanks! It's also a lot cleaner
than my patch :).

Thanks again,
-Jay

On Sun, Aug 6, 2017 at 12:15 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Hello,
>
> Jay Kamat <jaygkamat@gmail.com> writes:
>
>> I discovered a bug in the ox-md exporter and have created a patch to fix it:
>>
>> Previously, this image link:
>> [[https://git-scm.com/images/logo@2x.png]]
>>
>> would export to:
>> ![img](//git-scm.com/images/logo@2x.png)
>>
>> which is an invalid markdown image, and won't display properly in
>> browsers and other places.
>>
>> A workaround (which I have been using extremely heavily), is:
>> [[file:https://git-scm.com/images/logo@2x.png]]
>>
>> which exports to
>> ![img](https://git-scm.com/images/logo@2x.png)
>>
>> Which is the proper (unbroken) image link.
>>
>> I have attached a patch which fixes the first example, so it exports
>> the same link as the workaround (and is no longer broken).
>
> Thank you for the report and the patch. I have committed a slightly
> different change. Does it solve your issue?
>
>> My papers are currently being processed, but I thought I would post
>> this patch early to get feedback, since ideally I would like this bug
>> to be fixed as soon as possible :). Hopefully they'll be done before
>> the review is completed.
>
> Great! Let me know when the process is done.
>
> Regards,
>
> --
> Nicolas Goaziou

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

end of thread, other threads:[~2017-08-06 16:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-06  2:43 [PATCH] Fix ox-md remote image links export Jay Kamat
2017-08-06  7:15 ` Nicolas Goaziou
2017-08-06 16:10   ` Jay Kamat

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