From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: why prepend "file://" to abs paths in html output? Date: Mon, 10 Jul 2017 15:31:28 +0200 Message-ID: <877ezgwh8v.fsf@nicolasgoaziou.fr> References: <87lgnz43qk.fsf@nicolasgoaziou.fr> <87h8yn3tsa.fsf@nicolasgoaziou.fr> <87bmou4u8a.fsf@nicolasgoaziou.fr> <874lumfqk7.fsf@gmail.com> <877ezh51ns.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUYmm-0005T4-V4 for emacs-orgmode@gnu.org; Mon, 10 Jul 2017 09:31:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUYmj-0002nN-PX for emacs-orgmode@gnu.org; Mon, 10 Jul 2017 09:31:36 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:51821) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUYmj-0002mH-IF for emacs-orgmode@gnu.org; Mon, 10 Jul 2017 09:31:33 -0400 In-Reply-To: (Kaushal Modi's message of "Mon, 10 Jul 2017 12:53:10 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Kaushal Modi Cc: Carsten Dominik , Tim Cross , emacs-org list --=-=-= Content-Type: text/plain Hello, Kaushal Modi writes: > Can you please attach the patch? Oops. Here it is. Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-html-Implement-root-directory-for-absolute-links.patch >From 6eed5dcd4e585dd32e52571189cf395b1a532310 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 "
UP @@ -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 --=-=-=--