[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] why prepend "file://" to abs paths in html output?
From: |
Nicolas Goaziou |
Subject: |
Re: [O] why prepend "file://" to abs paths in html output? |
Date: |
Mon, 10 Jul 2017 15:31:28 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
Hello,
Kaushal Modi <address@hidden> writes:
> Can you please attach the patch?
Oops. Here it is.
Regards,
--
Nicolas Goaziou
>From 6eed5dcd4e585dd32e52571189cf395b1a532310 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <address@hidden>
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
- [O] why prepend "file://" to abs paths in html output?, Matt Price, 2017/07/07
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/08
- Re: [O] why prepend "file://" to abs paths in html output?, Kaushal Modi, 2017/07/08
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/08
- Re: [O] why prepend "file://" to abs paths in html output?, Carsten Dominik, 2017/07/08
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/08
- Re: [O] why prepend "file://" to abs paths in html output?, Tim Cross, 2017/07/08
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/09
- Re: [O] why prepend "file://" to abs paths in html output?, Kaushal Modi, 2017/07/10
- Re: [O] why prepend "file://" to abs paths in html output?,
Nicolas Goaziou <=
- Re: [O] why prepend "file://" to abs paths in html output?, Brett Viren, 2017/07/10
- Re: [O] why prepend "file://" to abs paths in html output?, Kaushal Modi, 2017/07/10
- Re: [O] why prepend "file://" to abs paths in html output?, Kaushal Modi, 2017/07/10
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/13
- Re: [O] why prepend "file://" to abs paths in html output?, Kaushal Modi, 2017/07/13
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/13
- Re: [O] why prepend "file://" to abs paths in html output?, Kaushal Modi, 2017/07/13
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/13
- Re: [O] why prepend "file://" to abs paths in html output?, Nicolas Goaziou, 2017/07/13
- Re: [O] why prepend "file://" to abs paths in html output?, Tim Cross, 2017/07/10