emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Export of irc links in ox-html
@ 2017-09-24  5:18 Jay Kamat
  2017-09-24  7:20 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Jay Kamat @ 2017-09-24  5:18 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi!

IRC links in ox-html are currently broken. There exists a special 'irc'
content handler on the web, telling browsers to open an irc link in an
external irc client. The format for such links seems identical to org
(irc:irc.freenode.net/user).

Previously links such as:

[[irc:irc.freenode.net/test][Irc link]]

Would export to 

<a href="irc.freenode.net/test">Irc link</a>

in ox-html.

After this tiny patch, it exports to:

<a href="irc:irc.freenode.net/test">Irc link</a>

which tells browsers such as firefox to open links in irc clients.

Let me know if you find any issues!

-Jay


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html.el-Fix-irc-links-exporting-to-link-to-local-.patch --]
[-- Type: text/x-diff, Size: 1023 bytes --]

From fa1a5ad3bf63158775ffa8ab3de37fb056103ab4 Mon Sep 17 00:00:00 2001
From: Jay Kamat <jaygkamat@gmail.com>
Date: Sun, 24 Sep 2017 01:11:42 -0400
Subject: [PATCH] ox-html.el: Fix irc links exporting to link to local files

* lisp/ox-html.el: Add "irc" to special link types which are exported
  as their link type and path separated by ':', so that browser irc
  content handlers work properly.
---
 lisp/ox-html.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index d91ca73622..8756cda7e5 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2973,7 +2973,7 @@ INFO is a plist holding contextual information.  See
 	 (desc (org-string-nw-p desc))
 	 (path
 	  (cond
-	   ((member type '("http" "https" "ftp" "mailto" "news"))
+	   ((member type '("http" "https" "ftp" "mailto" "news" "irc"))
 	    (url-encode-url (org-link-unescape (concat type ":" raw-path))))
 	   ((string= type "file")
 	    ;; Treat links to ".org" files as ".html", if needed.
-- 
2.11.0


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

* Re: [PATCH] Export of irc links in ox-html
  2017-09-24  5:18 [PATCH] Export of irc links in ox-html Jay Kamat
@ 2017-09-24  7:20 ` Nicolas Goaziou
  2017-09-24 16:28   ` Jay Kamat
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2017-09-24  7:20 UTC (permalink / raw)
  To: Jay Kamat; +Cc: emacs-orgmode

Hello,

Jay Kamat <jaygkamat@gmail.com> writes:

> IRC links in ox-html are currently broken.

They are not handled, which is slightly different.

> There exists a special 'irc'
> content handler on the web, telling browsers to open an irc link in an
> external irc client. The format for such links seems identical to org
> (irc:irc.freenode.net/user).
>
> Previously links such as:
>
> [[irc:irc.freenode.net/test][Irc link]]
>
> Would export to 
>
> <a href="irc.freenode.net/test">Irc link</a>
>
> in ox-html.

The proper fix would be to patch "org-irc.el" and add an export function
there. "irc" links are not default links in Org, so there is no reason
to hard-code them in "ox-html.el".

You can look into `org-info-export' in "org-info.el", which is an
example on how optional link types are handled.

Thank you!

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] Export of irc links in ox-html
  2017-09-24  7:20 ` Nicolas Goaziou
@ 2017-09-24 16:28   ` Jay Kamat
  2017-09-24 16:35     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Jay Kamat @ 2017-09-24 16:28 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

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

Hi Nicolas,

> The proper fix would be to patch "org-irc.el" and add an export function
> there. "irc" links are not default links in Org, so there is no reason
> to hard-code them in "ox-html.el".

Thanks for pointing that out! I didn't even realize up until now org had
support for custom link types.

I've attached a second patch which adds a new function to org-irc.el,
which seems to handle export of irc links in ox-md and ox-html
properly. I'm very new to this system, so please make sure it's correct,
and I'll be happy to follow up with corrections if it isn't!

Because I added support for md links in org-irc.el, I also removed the
workaround I added a while back for that in ox-md.el.

-Jay


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-irc.el-Add-proper-export-functions-for-irc.patch --]
[-- Type: text/x-diff, Size: 2199 bytes --]

From e6c824f363bf6959f0eb35e4b8208a14d2cbffcb Mon Sep 17 00:00:00 2001
From: Jay Kamat <jaygkamat@gmail.com>
Date: Sun, 24 Sep 2017 12:11:52 -0400
Subject: [PATCH] org-irc.el: Add proper export functions for irc

* lisp/org-irc.el (org-irc-export): Add a new function,
  org-irc-export, which properly exports irc links to html and markdown

* lisp/ox-md.el (org-md-link): Remove workaround to get irc links
  working properly in ox-md, and use org-irc's export functions instead
---
 lisp/org-irc.el | 20 +++++++++++++++++++-
 lisp/ox-md.el   |  2 +-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lisp/org-irc.el b/lisp/org-irc.el
index 5889f6d2fe..eee71aef52 100644
--- a/lisp/org-irc.el
+++ b/lisp/org-irc.el
@@ -71,7 +71,10 @@
 
 ;; Generic functions/config (extend these for other clients)
 
-(org-link-set-parameters "irc" :follow #'org-irc-visit :store #'org-irc-store-link)
+(org-link-set-parameters "irc"
+			 :follow #'org-irc-visit
+			 :store #'org-irc-store-link
+			 :export #'org-irc-export)
 
 (defun org-irc-visit (link)
   "Parse LINK and dispatch to the correct function based on the client found."
@@ -245,6 +248,21 @@ default."
       ;; no server match, make new connection
       (erc-select :server server :port port))))
 
+(defun org-irc-export (link description format)
+  "Export an info link.
+See `org-link-parameters' for details about LINK, DESCRIPTION and FORMAT."
+  (let* ((desc (or description link)))
+    (pcase format
+      (`html
+       (format "<a href=\"irc:%s\">%s</a>"
+	       link
+	       desc))
+      (`md
+       (format "[%s](irc:%s)"
+	       desc
+	       link))
+      (_ nil))))
+
 (provide 'org-irc)
 
 ;; Local variables:
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 5ba52e7faf..146956eedf 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -449,7 +449,7 @@ a communication channel."
      (t (let* ((raw-path (org-element-property :path link))
 	       (path
 		(cond
-		 ((member type '("http" "https" "ftp" "mailto" "irc"))
+		 ((member type '("http" "https" "ftp" "mailto"))
 		  (concat type ":" raw-path))
 		 ((string= type "file")
 		  (org-export-file-uri (funcall link-org-files-as-md raw-path)))
-- 
2.11.0


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

* Re: [PATCH] Export of irc links in ox-html
  2017-09-24 16:28   ` Jay Kamat
@ 2017-09-24 16:35     ` Nicolas Goaziou
  2017-09-25  1:34       ` Jay Kamat
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2017-09-24 16:35 UTC (permalink / raw)
  To: Jay Kamat; +Cc: emacs-orgmode

Jay Kamat <jaygkamat@gmail.com> writes:

> I've attached a second patch which adds a new function to org-irc.el,
> which seems to handle export of irc links in ox-md and ox-html
> properly. I'm very new to this system, so please make sure it's correct,
> and I'll be happy to follow up with corrections if it isn't!

Thank you!

> Because I added support for md links in org-irc.el, I also removed the
> workaround I added a while back for that in ox-md.el.

Good catch.

> +(defun org-irc-export (link description format)
> +  "Export an info link.

I applied your patch with info changed into IRC above.

Would you mind providing an ORG-NEWS entry about it?

Regards,

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

* Re: [PATCH] Export of irc links in ox-html
  2017-09-24 16:35     ` Nicolas Goaziou
@ 2017-09-25  1:34       ` Jay Kamat
  2017-09-25 13:52         ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Jay Kamat @ 2017-09-25  1:34 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

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

Hi Nicolas,

> Would you mind providing an ORG-NEWS entry about it?

I need to stop forgetting to do this :).

I've attached a patch which adds an entry to the 'Miscellaneous'
section. Please let me know if you think anything is wrong with it.

-Jay


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ORG-NEWS-Add-an-entry-for-supporting-export-in-org-i.patch --]
[-- Type: text/x-diff, Size: 915 bytes --]

From e321f926217460a506d6536ad494b1f25c247c4b Mon Sep 17 00:00:00 2001
From: Jay Kamat <jaygkamat@gmail.com>
Date: Sun, 24 Sep 2017 21:30:39 -0400
Subject: [PATCH] ORG-NEWS: Add an entry for supporting export in org-irc.el

---
 etc/ORG-NEWS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index d2fb264b18..7c69efa89d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -108,6 +108,12 @@ you should expect to see something like:
 ** Miscellaneous
 
 *** ~org-publish-resolve-external-link~ accepts a new optional argument.
+*** ~org-irc.el~ now supports exporting =irc:= links properly
+
+Previously, irc links were exported by ~ox-md~ and ~ox-html~ as normal
+file links, which lead to them being broken in web browsers. Now both
+of these exporters will properly export to =irc:= links, which will
+open properly in irc clients from web browsers.
 
 * Version 9.1
 
-- 
2.11.0


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

* Re: [PATCH] Export of irc links in ox-html
  2017-09-25  1:34       ` Jay Kamat
@ 2017-09-25 13:52         ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2017-09-25 13:52 UTC (permalink / raw)
  To: Jay Kamat; +Cc: emacs-orgmode

Hello,

Jay Kamat <jaygkamat@gmail.com> writes:

> I need to stop forgetting to do this :).
>
> I've attached a patch which adds an entry to the 'Miscellaneous'
> section. Please let me know if you think anything is wrong with it.

It looks goods. Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2017-09-25 13:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-24  5:18 [PATCH] Export of irc links in ox-html Jay Kamat
2017-09-24  7:20 ` Nicolas Goaziou
2017-09-24 16:28   ` Jay Kamat
2017-09-24 16:35     ` Nicolas Goaziou
2017-09-25  1:34       ` Jay Kamat
2017-09-25 13:52         ` Nicolas Goaziou

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