Skip to content

Commit e3bf83f

Browse files
committed
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.
1 parent f5c9ce8 commit e3bf83f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

etc/ORG-NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ blocks to LaTeX. This requires the =fvextra=, =float=, and (by
219219
default, but not necessarily) =tcolorbox= LaTeX packages be
220220
installed. It uses Emacs' font-lock information, and so tends to
221221
produce results superior to Minted or Listings.
222+
*** Support for =#+include=-ing URLs
223+
224+
=#+include: FILE= will now accept URLs as the file.
222225

223226
** New functions and changes in function arguments
224227

lisp/ox.el

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,15 +3229,18 @@ storing and resolving footnotes. It is created automatically."
32293229
value)
32303230
(prog1
32313231
(save-match-data
3232-
(let ((matched (match-string 1 value)))
3232+
(let ((matched (match-string 1 value))
3233+
stripped)
32333234
(when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
32343235
matched)
32353236
(setq location (match-string 2 matched))
32363237
(setq matched
32373238
(replace-match "" nil nil matched 1)))
3238-
(expand-file-name (org-strip-quotes matched)
3239-
dir)))
3240-
(setq value (replace-match "" nil nil value)))))
3239+
(setq stripped (org-strip-quotes matched))
3240+
(if (org-url-p stripped)
3241+
stripped
3242+
(expand-file-name stripped dir))))
3243+
(setq value (replace-match "" nil nil value)))))
32413244
(only-contents
32423245
(and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
32433246
value)
@@ -3273,7 +3276,7 @@ storing and resolving footnotes. It is created automatically."
32733276
(delete-region (point) (line-beginning-position 2))
32743277
(cond
32753278
((not file) nil)
3276-
((not (file-readable-p file))
3279+
((and (not (org-url-p file)) (not (file-readable-p file)))
32773280
(error "Cannot include file %s" file))
32783281
;; Check if files has already been parsed. Look after
32793282
;; inclusion lines too, as different parts of the same
@@ -3319,8 +3322,9 @@ storing and resolving footnotes. It is created automatically."
33193322
includer-file)))
33203323
(org-export-expand-include-keyword
33213324
(cons (list file lines) included)
3322-
(file-name-directory file)
3323-
footnotes)
3325+
(unless (org-url-p file)
3326+
(file-name-directory file))
3327+
footnotes)
33243328
(buffer-string)))))
33253329
;; Expand footnotes after all files have been
33263330
;; included. Footnotes are stored at end of buffer.
@@ -3343,7 +3347,7 @@ Org-Element. If LINES is non-nil only those lines are included.
33433347
Return a string of lines to be included in the format expected by
33443348
`org-export--prepare-file-contents'."
33453349
(with-temp-buffer
3346-
(insert-file-contents file)
3350+
(insert (org-file-contents file))
33473351
(unless (eq major-mode 'org-mode)
33483352
(let ((org-inhibit-startup t)) (org-mode)))
33493353
(condition-case err
@@ -3448,7 +3452,7 @@ the included document.
34483452
Optional argument INCLUDER is the file name where the inclusion
34493453
is to happen."
34503454
(with-temp-buffer
3451-
(insert-file-contents file)
3455+
(insert (org-file-contents file))
34523456
(when lines
34533457
(let* ((lines (split-string lines "-"))
34543458
(lbeg (string-to-number (car lines)))

0 commit comments

Comments
 (0)