From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Kaushal Modi <kaushal.modi@gmail.com>
Cc: Carsten Dominik <dominik@uva.nl>,
Tim Cross <theophilusx@gmail.com>,
emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: why prepend "file://" to abs paths in html output?
Date: Mon, 10 Jul 2017 15:31:28 +0200 [thread overview]
Message-ID: <877ezgwh8v.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <CAFyQvY0qztmUUmQjnPdk0tFA4vT0DP9Q-SrOOacfLYNykRKekg@mail.gmail.com> (Kaushal Modi's message of "Mon, 10 Jul 2017 12:53:10 +0000")
[-- Attachment #1: Type: text/plain, Size: 141 bytes --]
Hello,
Kaushal Modi <kaushal.modi@gmail.com> writes:
> Can you please attach the patch?
Oops. Here it is.
Regards,
--
Nicolas Goaziou
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-Implement-root-directory-for-absolute-links.patch --]
[-- Type: text/x-diff, Size: 3521 bytes --]
From 6eed5dcd4e585dd32e52571189cf395b1a532310 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Sun, 9 Jul 2017 12:40:49 +0200
Subject: [PATCH] ox-html: Implement root directory for absolute links
* lisp/ox-html.el (org-html-link-root): New variable.
(org-html-link): Use new variable.
(org-html-publish-to-html): Set root to base directory.
---
lisp/ox-html.el | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 2ceaf0722..edaec4df7 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -118,6 +118,7 @@
(:keywords "KEYWORDS" nil nil space)
(:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
(:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
+ (:html-link-root "HTML_LINK_ROOT" nil org-html-link-root)
(:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
(:html-link-up "HTML_LINK_UP" nil org-html-link-up)
(:html-mathjax "HTML_MATHJAX" nil "" space)
@@ -1403,6 +1404,18 @@ example."
:package-version '(Org . "8.1")
:type 'boolean)
+(defcustom org-html-link-root nil
+ "Directory considered as web root.
+When non-nil, all links to absolute file names belonging to this
+directory become root-relative URL. Otherwise, such links keep
+the \"file:\" scheme."
+ :group 'org-export-html
+ :version "26.1"
+ :package-version '(Org . "9.1")
+ :type '(choice (const :tag "No root directory" nil)
+ (directory :tag "Local web root"))
+ :safe #'string-or-null-p)
+
(defcustom org-html-home/up-format
"<div id=\"org-div-home-and-up\">
<a accesskey=\"h\" href=\"%s\"> UP </a>
@@ -2993,12 +3006,19 @@ INFO is a plist holding contextual information. See
(setq raw-path
(funcall link-org-files-as-html-maybe raw-path info))
;; If file path is absolute, prepend it with protocol
- ;; component - "file://".
+ ;; component - "file://" or make it a root-relative URL.
(cond
((file-name-absolute-p raw-path)
- (setq raw-path (org-export-file-uri raw-path)))
+ (let ((root (plist-get info :html-link-root)))
+ (setq raw-path
+ (if (and root (file-in-directory-p raw-path root))
+ (concat "/"
+ (file-relative-name
+ (expand-file-name raw-path)
+ root))
+ (org-export-file-uri raw-path)))))
((and home use-abs-url)
- (setq raw-path (concat (file-name-as-directory home) raw-path))))
+ (setq raw-path (expand-file-name raw-path home))))
;; Add search option, if any. A search option can be
;; relative to a custom-id, a headline title, a name or
;; a target.
@@ -3762,18 +3782,22 @@ Return output file's name."
;;;###autoload
(defun org-html-publish-to-html (plist filename pub-dir)
- "Publish an org file to HTML.
+ "Publish an Org file to HTML.
FILENAME is the filename of the Org file to be published. PLIST
is the property list for the given project. PUB-DIR is the
publishing directory.
Return output file name."
- (org-publish-org-to 'html filename
- (concat "." (or (plist-get plist :html-extension)
- org-html-extension
- "html"))
- plist pub-dir))
+ (org-publish-org-to
+ 'html
+ filename
+ (concat "." (or (plist-get plist :html-extension)
+ org-html-extension
+ "html"))
+ (org-combine-plists `(:html-link-root ,(plist-get plist :base-directory))
+ plist)
+ pub-dir))
(provide 'ox-html)
--
2.13.2
next prev parent reply other threads:[~2017-07-10 13:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-08 0:38 why prepend "file://" to abs paths in html output? Matt Price
2017-07-08 10:33 ` Nicolas Goaziou
2017-07-08 12:37 ` Kaushal Modi
2017-07-08 14:08 ` Nicolas Goaziou
2017-07-08 14:19 ` Carsten Dominik
2017-07-08 19:13 ` Nicolas Goaziou
2017-07-08 23:37 ` Tim Cross
2017-07-09 10:45 ` Nicolas Goaziou
2017-07-10 12:53 ` Kaushal Modi
2017-07-10 13:31 ` Nicolas Goaziou [this message]
2017-07-10 13:58 ` Brett Viren
2017-07-10 19:54 ` Kaushal Modi
2017-07-10 21:44 ` Kaushal Modi
2017-07-13 12:39 ` Nicolas Goaziou
2017-07-13 12:50 ` Kaushal Modi
2017-07-13 12:55 ` Nicolas Goaziou
2017-07-13 13:01 ` Kaushal Modi
2017-07-13 13:14 ` Nicolas Goaziou
2017-07-13 12:46 ` Nicolas Goaziou
2017-07-10 22:12 ` Tim Cross
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=877ezgwh8v.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=dominik@uva.nl \
--cc=emacs-orgmode@gnu.org \
--cc=kaushal.modi@gmail.com \
--cc=theophilusx@gmail.com \
/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).