ox: Support #+include-ing URLs

* lisp/ox.el (org-export--prepare-file-contents,
org-export--inclusion-absolute-lines): Replace instances of
`(insert-file-contents FILE)' with `(insert (org-file-contents FILE))',
as in `org--collect-keywords-1'.
(org-export-expand-include-keyword): Tweak to accept a URL as FILE, and
not perform the standard "file exists and is readable" check.

* etc/ORG-NEWS: Mention this change in behaviour.
This commit is contained in:
TEC 2022-06-05 22:25:22 +08:00
parent f5c9ce8f06
commit e3bf83fe82
Signed by: tec
GPG Key ID: 779591AFDB81F06C
2 changed files with 16 additions and 9 deletions

View File

@ -219,6 +219,9 @@ blocks to LaTeX. This requires the =fvextra=, =float=, and (by
default, but not necessarily) =tcolorbox= LaTeX packages be default, but not necessarily) =tcolorbox= LaTeX packages be
installed. It uses Emacs' font-lock information, and so tends to installed. It uses Emacs' font-lock information, and so tends to
produce results superior to Minted or Listings. produce results superior to Minted or Listings.
*** Support for =#+include=-ing URLs
=#+include: FILE= will now accept URLs as the file.
** New functions and changes in function arguments ** New functions and changes in function arguments

View File

@ -3229,14 +3229,17 @@ storing and resolving footnotes. It is created automatically."
value) value)
(prog1 (prog1
(save-match-data (save-match-data
(let ((matched (match-string 1 value))) (let ((matched (match-string 1 value))
stripped)
(when (string-match "\\(::\\(.*?\\)\\)\"?\\'" (when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
matched) matched)
(setq location (match-string 2 matched)) (setq location (match-string 2 matched))
(setq matched (setq matched
(replace-match "" nil nil matched 1))) (replace-match "" nil nil matched 1)))
(expand-file-name (org-strip-quotes matched) (setq stripped (org-strip-quotes matched))
dir))) (if (org-url-p stripped)
stripped
(expand-file-name stripped dir))))
(setq value (replace-match "" nil nil value))))) (setq value (replace-match "" nil nil value)))))
(only-contents (only-contents
(and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?" (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
@ -3273,7 +3276,7 @@ storing and resolving footnotes. It is created automatically."
(delete-region (point) (line-beginning-position 2)) (delete-region (point) (line-beginning-position 2))
(cond (cond
((not file) nil) ((not file) nil)
((not (file-readable-p file)) ((and (not (org-url-p file)) (not (file-readable-p file)))
(error "Cannot include file %s" file)) (error "Cannot include file %s" file))
;; Check if files has already been parsed. Look after ;; Check if files has already been parsed. Look after
;; inclusion lines too, as different parts of the same ;; inclusion lines too, as different parts of the same
@ -3319,7 +3322,8 @@ storing and resolving footnotes. It is created automatically."
includer-file))) includer-file)))
(org-export-expand-include-keyword (org-export-expand-include-keyword
(cons (list file lines) included) (cons (list file lines) included)
(file-name-directory file) (unless (org-url-p file)
(file-name-directory file))
footnotes) footnotes)
(buffer-string))))) (buffer-string)))))
;; Expand footnotes after all files have been ;; Expand footnotes after all files have been
@ -3343,7 +3347,7 @@ Org-Element. If LINES is non-nil only those lines are included.
Return a string of lines to be included in the format expected by Return a string of lines to be included in the format expected by
`org-export--prepare-file-contents'." `org-export--prepare-file-contents'."
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert (org-file-contents file))
(unless (eq major-mode 'org-mode) (unless (eq major-mode 'org-mode)
(let ((org-inhibit-startup t)) (org-mode))) (let ((org-inhibit-startup t)) (org-mode)))
(condition-case err (condition-case err
@ -3448,7 +3452,7 @@ the included document.
Optional argument INCLUDER is the file name where the inclusion Optional argument INCLUDER is the file name where the inclusion
is to happen." is to happen."
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert (org-file-contents file))
(when lines (when lines
(let* ((lines (split-string lines "-")) (let* ((lines (split-string lines "-"))
(lbeg (string-to-number (car lines))) (lbeg (string-to-number (car lines)))