ox: Fix extra character deletion after link

* lisp/ox.el (org-export--update-included-link): Account
for :post-blank property when inserting back the link.
* testing/lisp/test-ox.el (test-org-export/expand-include/links): Add
test.

Fixes bug#39173.
This commit is contained in:
Nicolas Goaziou 2020-02-11 18:59:52 +01:00
parent 713c8d5aba
commit 1af8c5a0df
2 changed files with 29 additions and 6 deletions

View File

@ -3461,15 +3461,16 @@ Move point after the link."
(goto-char (org-element-property :end link))
(let ((new-path (file-relative-name (expand-file-name path file-dir)
includer-dir))
(new-link (org-element-copy link))
(contents (and (org-element-property :contents-begin link)
(buffer-substring
(org-element-property :contents-begin link)
(org-element-property :contents-end link)))))
(new-link (org-element-copy link)))
(org-element-put-property new-link :path new-path)
(when (org-element-property :contents-begin link)
(org-element-adopt-elements new-link
(buffer-substring
(org-element-property :contents-begin link)
(org-element-property :contents-end link))))
(delete-region (org-element-property :begin link)
(org-element-property :end link))
(insert (org-element-link-interpreter new-link contents))))))
(insert (org-element-interpret-data new-link))))))
(defun org-export--prepare-file-contents
(file &optional lines ind minlevel id footnotes includer)

View File

@ -1440,6 +1440,28 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(kill-buffer buffer))
(when (file-exists-p subdir) (delete-directory subdir t))
(when (file-exists-p includer) (delete-file includer)))))))
;; Preserve relative bracket links without description.
(should
(string-suffix-p
"foo.org]] :tag:"
(let* ((subdir (make-temp-file "org-includee-" t))
(includee (expand-file-name "includee.org" subdir))
(includer (make-temp-file "org-includer-")))
(write-region "[[file:foo.org]] :tag:" nil includee)
(write-region (format "#+INCLUDE: %S"
(file-relative-name includee
temporary-file-directory))
nil includer)
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
(with-current-buffer buffer (set-buffer-modified-p nil))
(kill-buffer buffer))
(when (file-exists-p subdir) (delete-directory subdir t))
(when (file-exists-p includer) (delete-file includer)))))))
;; Preserve relative bracket links with description.
(should
(string-prefix-p