emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Pablo Aguado <aguadopd@hotmail.com>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: [BUG] Exporting to text fails when there are broken links
Date: Wed, 24 Apr 2024 03:37:16 +0000	[thread overview]
Message-ID: <SA1P223MB070291E02E95707C31342244C2102@SA1P223MB0702.NAMP223.PROD.OUTLOOK.COM> (raw)


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


             reply	other threads:[~2024-04-24  3:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-24  3:37 Pablo Aguado [this message]
2024-04-24 12:47 ` [BUG] Exporting to text fails when there are broken links Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SA1P223MB070291E02E95707C31342244C2102@SA1P223MB0702.NAMP223.PROD.OUTLOOK.COM \
    --to=aguadopd@hotmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).