Fixed issue with links to other org files (#34)

This commit is contained in:
Masanao Igarashi
2019-08-09 17:47:22 +09:00
parent 973ef2b539
commit 038bce090f

View File

@@ -94,9 +94,10 @@
(:rst-link-use-abs-url nil "rst-link-use-abs-url" org-rst-link-use-abs-url) (:rst-link-use-abs-url nil "rst-link-use-abs-url" org-rst-link-use-abs-url)
(:rst-inline-images nil nil org-rst-inline-images) (:rst-inline-images nil nil org-rst-inline-images)
(:rst-inline-image-rules nil nil org-rst-inline-image-rules) (:rst-inline-image-rules nil nil org-rst-inline-image-rules)
(:rst-link-org-files-as-html nil nil org-rst-link-org-files-as-html) (:rst-link-org-files-as-rst nil nil org-rst-link-org-files-as-rst)
(:rst-link-home "RST_LINK_HOME" nil org-rst-link-home) (:rst-link-home "RST_LINK_HOME" nil org-rst-link-home)
(:rst-link-use-ref-role nil nil org-rst-link-use-ref-role) (:rst-link-use-ref-role nil nil org-rst-link-use-ref-role)
(:rst-extension nil nil org-rst-extension)
(:rst-text-markup-alist nil nil org-rst-text-markup-alist) (:rst-text-markup-alist nil nil org-rst-text-markup-alist)
(:rst-quote-margin nil nil org-rst-quote-margin) (:rst-quote-margin nil nil org-rst-quote-margin)
(:rst-headline-underline-characters nil nil org-rst-headline-underline-characters) (:rst-headline-underline-characters nil nil org-rst-headline-underline-characters)
@@ -126,21 +127,28 @@
:group 'org-export) :group 'org-export)
(defcustom org-rst-link-org-files-as-html t (defcustom org-rst-extension "rst"
"Non-nil means make file links to `file.org' point to `file.html'. "The extension for exported reStructuredText files."
When `org-mode' is exporting an `org-mode' file to HTML, links to :group 'org-export-rst
non-html files are directly put into a href tag in HTML. :type 'string)
(defcustom org-rst-link-org-files-as-rst t
"Non-nil means make file links to `file.org' point to `file.rst'.
When `org-mode' is exporting an `org-mode' file to reStructuredText,
links to non-rst files are directly put into a href tag in
reStructuredText.
However, links to other Org mode files (recognized by the extension However, links to other Org mode files (recognized by the extension
`.org.) should become links to the corresponding HTML `.org.) should become links to the corresponding reStructuredText
file, assuming that the linked `org-mode' file will also be file, assuming that the linked `org-mode' file will also be
converted to HTML. converted to reStructuredText.
When nil, the links still point to the plain \".org\" file." When nil, the links still point to the plain \".org\" file."
:group 'org-export-rst :group 'org-export-rst
:type 'boolean) :type 'boolean)
(defcustom org-rst-link-home "" (defcustom org-rst-link-home ""
"Where should the \"HOME\" link of exported HTML pages lead?" "Where should the \"HOME\" link of exported rst files lead?"
:group 'org-export-rst :group 'org-export-rst
:type '(string :tag "File or URL")) :type '(string :tag "File or URL"))
@@ -924,20 +932,20 @@ if its description is a single link targeting an image file."
DESC is the description part of the link, or the empty string. DESC is the description part of the link, or the empty string.
INFO is a plist holding contextual information." INFO is a plist holding contextual information."
(let* ((home (when (plist-get info :html-link-home) (let* ((home (when (plist-get info :rst-link-home)
(org-trim (plist-get info :html-link-home)))) (org-trim (plist-get info :rst-link-home))))
(use-abs-url (plist-get info :html-link-use-abs-url)) (use-abs-url (plist-get info :rst-link-use-abs-url))
(link-org-files-as-html-maybe (link-org-files-as-rst-maybe
(function (function
(lambda (raw-path info) (lambda (raw-path info)
"Treat links to `file.org' as links to `file.html', if needed. "Treat links to `file.org' as links to `file.rst', if needed.
See `org-rst-link-org-files-as-html'." See `org-rst-link-org-files-as-rst'."
(cond (cond
((and (plist-get info :rst-link-org-files-as-html) ((and (plist-get info :rst-link-org-files-as-rst)
(string= ".org" (string= ".org"
(downcase (file-name-extension raw-path ".")))) (downcase (file-name-extension raw-path "."))))
(concat (file-name-sans-extension raw-path) "." (concat (file-name-sans-extension raw-path) "."
(plist-get info :html-extension))) (plist-get info :rst-extension)))
(t raw-path))))) (t raw-path)))))
(type (org-element-property :type link)) (type (org-element-property :type link))
(raw-path (org-element-property :path link)) (raw-path (org-element-property :path link))
@@ -949,9 +957,9 @@ INFO is a plist holding contextual information."
(org-link-unescape (org-link-unescape
(concat type ":" raw-path)))) (concat type ":" raw-path))))
((string= type "file") ((string= type "file")
;; Treat links to ".org" files as ".html", if needed. ;; Treat links to ".org" files as ".rst", if needed.
(setq raw-path (setq raw-path
(funcall link-org-files-as-html-maybe raw-path info)) (funcall link-org-files-as-rst-maybe raw-path info))
(cond ((and home use-abs-url) (cond ((and home use-abs-url)
(setq raw-path (setq raw-path
(concat (file-name-as-directory home) raw-path))) (concat (file-name-as-directory home) raw-path)))
@@ -1690,8 +1698,11 @@ contents of hidden elements.
Return output file's name." Return output file's name."
(interactive) (interactive)
(let ((outfile (org-export-output-file-name ".rst" subtreep))) (let* ((extension (concat "." (or (plist-get ext-plist :rst-extension)
(org-export-to-file 'rst outfile org-rst-extension
"rst")))
(file (org-export-output-file-name extension subtreep)))
(org-export-to-file 'rst file
async subtreep visible-only body-only ext-plist))) async subtreep visible-only body-only ext-plist)))
;;;###autoload ;;;###autoload