* [BUG] Exporting to text fails when there are broken links
@ 2024-04-24 3:37 Pablo Aguado
2024-04-24 12:47 ` Ihor Radchenko
0 siblings, 1 reply; 2+ messages in thread
From: Pablo Aguado @ 2024-04-24 3:37 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
Org mode version 9.6.15
* CURRENT BEHAVIOR
Exporting to text fails when ~org-export-with-broken-links~ is set to ~mark~. [[help:org-export-with-broken-links]]
The following are minimal examples using source blocks in org. I'm using an LLM-generated function to call ~org-export-string-as~, but there might be an easier option with arguments and blocks. You can also replicate by calling ~org-export-dispatch~ -> Export to plain text -> As ASCII buffer (or Latin1 or UTF-8).
#+begin_src elisp
(defun org-src-to-text (block-name)
"Convert the content of a named Org source block to text."
(org-element-map (org-element-parse-buffer) 'src-block
(lambda (src)
(when (string= block-name (org-element-property :name src))
(let ((src-block (org-element-property :value src)))
(princ (org-export-string-as src-block 'ascii t)))))))
#+end_src
#+RESULTS:
: org-src-to-text
** broken-links:nil
#+NAME: source-broken-links-nil
#+begin_src org
,#+OPTIONS: broken-links:nil
,* Some title
1. This [[file:existing-file.org][link1]] is exported correctly to text.
2. This [[file:{filename}existing-file.org][link2]] is exported correctly to text.
3. This [[file:{filename}test-nonexistent-file.org][link3]] is exported correctly to text.
4. This [[file:test-nonexistent-file.org][link4]] is exported correctly to text.
5. This [[{filename}test-nonexistent-file.org][link5]] is NOT exported correctly to text.
#+end_src
#+begin_src elisp :results output
(org-src-to-text "source-broken-links-nil")
#+end_src
This fails with =org-export-data: Unable to resolve link: "{filename}test-nonexistent-file.org"=
** source-broken-links-t
#+NAME: source-broken-links-t
#+begin_src org
,#+OPTIONS: broken-links:t
,* Some title
1. This [[file:existing-file.org][link1]] is exported correctly to text.
2. This [[file:{filename}existing-file.org][link2]] is exported correctly to text.
3. This [[file:{filename}test-nonexistent-file.org][link3]] is exported correctly to text.
4. This [[file:test-nonexistent-file.org][link4]] is exported correctly to text.
5. This [[{filename}test-nonexistent-file.org][link5]] is NOT exported correctly to text.
#+end_src
#+RESULTS: source-broken-links-t
#+begin_src elisp :results output
(org-src-to-text "source-broken-links-t")
#+end_src
#+RESULTS:
#+begin_example
,* Some title
1. This [link1] is exported correctly to text.
2. This [link2] is exported correctly to text.
3. This [link3] is exported correctly to text.
4. This [link4] is exported correctly to text.
5. This is NOT exported correctly to text.
[link1] <file:existing-file.org>
[link2] <file:{filename}existing-file.org>
[link3] <file:{filename}test-nonexistent-file.org>
[link4] <file:test-nonexistent-file.org>
#+end_example
** source-broken-links-mark
#+NAME: source-broken-links-mark
#+begin_src org
,#+OPTIONS: broken-links:mark
,* Some title
1. This [[file:existing-file.org][link1]] is exported correctly to text.
2. This [[file:{filename}existing-file.org][link2]] is exported correctly to text.
3. This [[file:{filename}test-nonexistent-file.org][link3]] is exported correctly to text.
4. This [[file:test-nonexistent-file.org][link4]] is exported correctly to text.
5. This [[{filename}test-nonexistent-file.org][link5]] is NOT exported correctly to text.
#+end_src
#+begin_src elisp :results output
(org-src-to-text "source-broken-links-mark")
#+end_src
#+RESULTS:
: [BROKEN LINK: {filename}test-nonexistent-file.org]
NOTE THAT ONLY THE BROKEN LINK IS SHOWN HERE! BUT NOT THE REST OF THE TEXT.
* EXPECTED BEHAVIOR
As with other backends (like ~html~), I'd expect the correctly exported text, not only the broken link.
#+begin_example
,* Some title
1. This [link1] is exported correctly to text.
2. This [link2] is exported correctly to text.
3. This [link3] is exported correctly to text.
4. This [link4] is exported correctly to text.
5. This [BROKEN LINK: {filename}test-nonexistent-file.org]is NOT exported correctly to text.
[link1] <file:existing-file.org>
[link2] <file:{filename}existing-file.org>
[link3] <file:{filename}test-nonexistent-file.org>
[link4] <file:test-nonexistent-file.org>
#+end_example
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [BUG] Exporting to text fails when there are broken links
2024-04-24 3:37 [BUG] Exporting to text fails when there are broken links Pablo Aguado
@ 2024-04-24 12:47 ` Ihor Radchenko
0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2024-04-24 12:47 UTC (permalink / raw)
To: Pablo Aguado; +Cc: emacs-orgmode@gnu.org
Pablo Aguado <aguadopd@hotmail.com> writes:
> #+NAME: source-broken-links-mark
> #+begin_src org
> ,#+OPTIONS: broken-links:mark
>
> ,* Some title
>
> ...
> 5. This [[{filename}test-nonexistent-file.org][link5]] is NOT exported correctly to text.
> #+end_src
>
> #+begin_src elisp :results output
> (org-src-to-text "source-broken-links-mark")
> #+end_src
>
> #+RESULTS:
> : [BROKEN LINK: {filename}test-nonexistent-file.org]
>
>
> NOTE THAT ONLY THE BROKEN LINK IS SHOWN HERE! BUT NOT THE REST OF THE TEXT.
Thanks for reporting!
Fixed, on bugfix.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d6353b283
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-24 12:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-24 3:37 [BUG] Exporting to text fails when there are broken links Pablo Aguado
2024-04-24 12:47 ` Ihor Radchenko
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.