* Feature request: Allow export to convert broken links to plain text
@ 2023-04-13 22:55 Janek Fischer
2023-04-15 6:50 ` Hanno Perrey
2023-04-17 13:56 ` Ihor Radchenko
0 siblings, 2 replies; 11+ messages in thread
From: Janek Fischer @ 2023-04-13 22:55 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 440 bytes --]
I am looking for exactly the feature in https://lists.gnu.org/r/emacs-orgmode/2019-01/msg00203.html:
I have a note with many links, but would like to export that note as landing page as text stripped of links.
Has there been any progress in the last 4 years on this,
or any hint on how to get this now?
Regards
Janek
---
CTO https://forensicdiscovery.de and https://software-challenge.deSoftware Engineering Student @ https://code.berlin
[-- Attachment #2: Type: text/html, Size: 1397 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2023-04-13 22:55 Feature request: Allow export to convert broken links to plain text Janek Fischer
@ 2023-04-15 6:50 ` Hanno Perrey
2023-04-17 13:56 ` Ihor Radchenko
1 sibling, 0 replies; 11+ messages in thread
From: Hanno Perrey @ 2023-04-15 6:50 UTC (permalink / raw)
To: Janek Fischer; +Cc: emacs-orgmode
Hej Janek,
> I have a note with many links, but would like to export that note as
> landing page as text stripped of links.
I have had a similar need recently where I wanted to export a document
filled with inks to org-roam nodes and other org headlines via id links.
I was able to strip the links on export for just this type while
preserving other link types:
#+begin_src emacs-lisp
(defun my-link-remover (link contents info) contents)
(org-link-set-parameters "id" :export 'my-link-remover)
#+end_src
This could of course be extended to actually check the link and only
remove it if it points to nowhere.
Hope this points you in a useful direction!
Best wishes,
Hanno
--
Hanno Perrey
https://hoowl.se
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2023-04-13 22:55 Feature request: Allow export to convert broken links to plain text Janek Fischer
2023-04-15 6:50 ` Hanno Perrey
@ 2023-04-17 13:56 ` Ihor Radchenko
1 sibling, 0 replies; 11+ messages in thread
From: Ihor Radchenko @ 2023-04-17 13:56 UTC (permalink / raw)
To: Janek Fischer; +Cc: emacs-orgmode@gnu.org
Janek Fischer <janek.fischer@protonmail.com> writes:
> I am looking for exactly the feature in https://lists.gnu.org/r/emacs-orgmode/2019-01/msg00203.html:
> I have a note with many links, but would like to export that note as landing page as text stripped of links.
>
> Has there been any progress in the last 4 years on this,
> or any hint on how to get this now?
For example, you can make all the code throwing 'org-link-broken return
a list of (PATH LINK) instead of just PATH. Then, `org-export-data' and
`org-export-with-broken-links' may be modified to optionally do
something with the LINK object itself.
Patches welcome!
--
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] 11+ messages in thread
* Feature request: Allow export to convert broken links to plain text
@ 2019-01-12 20:38 Ryan Thompson
2019-01-12 20:42 ` Ryan Thompson
2019-01-13 17:50 ` Berry, Charles
0 siblings, 2 replies; 11+ messages in thread
From: Ryan Thompson @ 2019-01-12 20:38 UTC (permalink / raw)
To: Org-Mode List
[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]
Hi all,
I have a use case where I'd like for Org Mode to remove broken links while
preserving their text when exporting. In particular, I'm exporting the same
file multiple times with different sets of headlines excluded each time,
and as a result I have to be careful of linking to headlines that might not
be present in every export. It would be much easier if such links could
simply be converted back to plain text for that export, while remaining as
a link for any exports that *do* include the target headline. None of the
existing settings do quite what I want. The "mark" option comes closest. I
basically want "mark" but without adding any additional text around the
link's text. Would the developers be willing to merge such a feature if I
wrote it? I would implement it by adding another possible value to
"org-export-with-broken-links", perhaps calling it something like "unlink"
or "strip" (suggestions for a better name welcome). Alternatively, I could
implement an option to dispatch broken link handling to an arbitrary
function.
Thanks,
Ryan Thompson
[-- Attachment #2: Type: text/html, Size: 1653 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2019-01-12 20:38 Ryan Thompson
@ 2019-01-12 20:42 ` Ryan Thompson
2019-01-13 17:50 ` Berry, Charles
1 sibling, 0 replies; 11+ messages in thread
From: Ryan Thompson @ 2019-01-12 20:42 UTC (permalink / raw)
To: Org-Mode List
[-- Attachment #1: Type: text/plain, Size: 1368 bytes --]
(Apologies for the double post of this email; due to a misconfiguration of
my mailer, I believed my first email hadn't gone through until I remembered
to check the archives.)
On Sat, Jan 12, 2019 at 12:38 PM Ryan Thompson <rct@thompsonclan.org> wrote:
> Hi all,
>
> I have a use case where I'd like for Org Mode to remove broken links
> while preserving their text when exporting. In particular, I'm exporting
> the same file multiple times with different sets of headlines excluded each
> time, and as a result I have to be careful of linking to headlines that
> might not be present in every export. It would be much easier if such links
> could simply be converted back to plain text for that export, while
> remaining as a link for any exports that *do* include the target headline.
> None of the existing settings do quite what I want. The "mark" option comes
> closest. I basically want "mark" but without adding any additional text
> around the link's text. Would the developers be willing to merge such a
> feature if I wrote it? I would implement it by adding another possible
> value to "org-export-with-broken-links", perhaps calling it something like
> "unlink" or "strip" (suggestions for a better name welcome). Alternatively,
> I could implement an option to dispatch broken link handling to an
> arbitrary function.
>
> Thanks,
>
> Ryan Thompson
>
>
[-- Attachment #2: Type: text/html, Size: 2285 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2019-01-12 20:38 Ryan Thompson
2019-01-12 20:42 ` Ryan Thompson
@ 2019-01-13 17:50 ` Berry, Charles
2019-01-13 21:33 ` Ryan Thompson
1 sibling, 1 reply; 11+ messages in thread
From: Berry, Charles @ 2019-01-13 17:50 UTC (permalink / raw)
To: Ryan Thompson; +Cc: Org-Mode List
> On Jan 12, 2019, at 12:38 PM, Ryan Thompson <rct@thompsonclan.org> wrote:
>
> Hi all,
>
> I have a use case where I'd like for Org Mode to remove broken links while preserving their text when exporting. In particular, I'm exporting the same file multiple times with different sets of headlines excluded each time, and as a result I have to be careful of linking to headlines that might not be present in every export. It would be much easier if such links could simply be converted back to plain text for that export, while remaining as a link for any exports that *do* include the target headline. None of the existing settings do quite what I want. The "mark" option comes closest.
> I basically want "mark" but without adding any additional text around the link's text.
Sounds like a good use case for a filter. See
(info "(org) Advanced Export Configuration")
and scroll down to the `Filters' section.
Just use the `broken-links:mark' option and set up your link filter to strip the `BROKEN LINK:' part.
HTH,
Chuck
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2019-01-13 17:50 ` Berry, Charles
@ 2019-01-13 21:33 ` Ryan Thompson
2019-01-13 22:34 ` Berry, Charles
0 siblings, 1 reply; 11+ messages in thread
From: Ryan Thompson @ 2019-01-13 21:33 UTC (permalink / raw)
To: Berry, Charles; +Cc: Org-Mode List
[-- Attachment #1: Type: text/plain, Size: 1719 bytes --]
Hi,
This sounds like a good idea, but unfortunately it seems that the
`broken-links:mark'
option doesn't preserve the text of the link. In fact, looking at the
source, the code that handles broken link errors doesn't even have access
to the link's text, only the link target, so it's already too late once the
org-link-broken signal is thrown. This also means that the implementation I
was considering won't work.
So, it looks like I need to intercept execution earlier in the export
process. Any ideas on how to do that?
Thanks,
Ryan
On Sun, Jan 13, 2019 at 9:50 AM Berry, Charles <ccberry@ucsd.edu> wrote:
>
>
> > On Jan 12, 2019, at 12:38 PM, Ryan Thompson <rct@thompsonclan.org>
> wrote:
> >
> > Hi all,
> >
> > I have a use case where I'd like for Org Mode to remove broken links
> while preserving their text when exporting. In particular, I'm exporting
> the same file multiple times with different sets of headlines excluded each
> time, and as a result I have to be careful of linking to headlines that
> might not be present in every export. It would be much easier if such links
> could simply be converted back to plain text for that export, while
> remaining as a link for any exports that *do* include the target headline.
> None of the existing settings do quite what I want. The "mark" option comes
> closest.
>
>
> > I basically want "mark" but without adding any additional text around
> the link's text.
>
>
> Sounds like a good use case for a filter. See
>
> (info "(org) Advanced Export Configuration")
>
> and scroll down to the `Filters' section.
>
> Just use the `broken-links:mark' option and set up your link filter to
> strip the `BROKEN LINK:' part.
>
> HTH,
>
> Chuck
>
>
>
>
[-- Attachment #2: Type: text/html, Size: 2574 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2019-01-13 21:33 ` Ryan Thompson
@ 2019-01-13 22:34 ` Berry, Charles
2023-09-10 4:13 ` Ryan C. Thompson
0 siblings, 1 reply; 11+ messages in thread
From: Berry, Charles @ 2019-01-13 22:34 UTC (permalink / raw)
To: Ryan Thompson; +Cc: Org-Mode List
> On Jan 13, 2019, at 1:33 PM, Ryan Thompson <rct@thompsonclan.org> wrote:
>
> Hi,
>
> This sounds like a good idea, but unfortunately it seems that the `broken-links:mark' option doesn't preserve the text of the link. In fact, looking at the source, the code that handles broken link errors doesn't even have access to the link's text, only the link target, so it's already too late once the org-link-broken signal is thrown. This also means that the implementation I was considering won't work.
>
> So, it looks like I need to intercept execution earlier in the export process. Any ideas on how to do that?
Looks like your original idea to revise `org-export-data' might be best.
IIUC, you need to add the link text to the SIGNAL-DATA in each of the places where `org-export-resolve-*-link' functions call `signal', then modify `org-export-data' to ignore the addition for `mark' and add it back for your new `mark-with-text' option.
HTH,
Chuck
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2019-01-13 22:34 ` Berry, Charles
@ 2023-09-10 4:13 ` Ryan C. Thompson
2023-09-11 17:12 ` Berry, Charles
0 siblings, 1 reply; 11+ messages in thread
From: Ryan C. Thompson @ 2023-09-10 4:13 UTC (permalink / raw)
To: Berry, Charles; +Cc: Org-Mode List
[-- Attachment #1: Type: text/plain, Size: 2919 bytes --]
On 1/13/19 5:34 PM, Berry, Charles wrote:
> Looks like your original idea to revise `org-export-data' might be best.
>
> IIUC, you need to add the link text to the SIGNAL-DATA in each of the places where `org-export-resolve-*-link' functions call `signal', then modify `org-export-data' to ignore the addition for `mark' and add it back for your new `mark-with-text' option.
>
> HTH,
>
> Chuck
Years later, I became annoyed enough by this to attempt to fix it again.
Unfortunately, I looked into changing all the functions that signal
org-link-broken, and not all of them can be modified in the way you
described, at least not easily. Instead, I came up with a fairly clean
alternative solution: define a new link type "maybe" using
org-link-set-parameters with an :export function that pulls out the real
link transcoder from the backend and calls it, but then implements my
desired behavior if that transcoder throws an error. This allows you to
prefix any link's path with "maybe:" to have it magically become plain
text if it can't be resolved during export. Here's the implementation:
(org-link-set-parameters
"maybe"
:follow
(lambda (path prefix)
(condition-case err
(org-link-open-from-string (format "[[%s]]" path))
(error (message "Failed to open maybe link %S" path))))
;; This must be a lambda so it is self-contained
:export
(lambda (path desc backend &optional info)
(when (symbolp backend)
(setq backend (org-export-get-backend backend)))
;; Generate the non-maybe version of the link, and call the
;; backend's appropriate transcoder on it, but catch any error
;; thrown and just replace the link with its text instead.
(let* ((real-link
(with-temp-buffer
(save-excursion (insert "[[" path "][" desc "]]"))
(org-element-link-parser)))
(real-link-transcoder (cdr (assoc 'link
(org-export-get-all-transcoders backend)))))
(condition-case err
(funcall real-link-transcoder real-link desc info)
(error
(message "Skipping error during maybe link transcoding: %S" err)
(or desc path))))))
Using the above code, the following org file can be successfully
exported to HTML, with the broken/invalid links converted to just plain
text.
* First heading
:PROPERTIES:
:CUSTOM_ID: heading1
:END:
- [[maybe:maybe:maybe:https://google.com][Maybe google]]
- [[maybe:#heading1][Link to first heading]]
- [[maybe:#heading2][Link to second heading]]
- [[maybe:#heading3][Link to third(?) heading]]
- [[maybe:blarg:notalink][This is an invalid link]]
* Second heading
:PROPERTIES:
:CUSTOM_ID: heading2
:END:
So, this isn't an ideal solution, since it requires me to prefix any
potential offending links with "maybe:". But it's good enough for me.
Regards,
Ryan
[-- Attachment #2: Type: text/html, Size: 4178 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Feature request: Allow export to convert broken links to plain text
2023-09-10 4:13 ` Ryan C. Thompson
@ 2023-09-11 17:12 ` Berry, Charles
0 siblings, 0 replies; 11+ messages in thread
From: Berry, Charles @ 2023-09-11 17:12 UTC (permalink / raw)
To: Ryan C. Thompson; +Cc: Berry, Charles, Org-Mode List
Ryan,
> On Sep 9, 2023, at 9:13 PM, Ryan C. Thompson <rct@thompsonclan.org> wrote:
>
> So, this isn't an ideal solution, since it requires me to prefix any potential offending links with "maybe:". But it's good enough for me.
>
It is good that you have a solution, albeit with the caveat you mention above.
A couple of thoughts:
There is a hook that operates on the copy buffer before parsing viz. "org-export-before-parsing-functions is a variable defined in ‘ox.el’." (In older versions, it was org-export-before-parsing-hook.) Maybe you can add a hook that will add that prefix to all links, so you do not need to put it in your working files.
Or you could write an elisp macro that takes two arguments (link, desc) and uses them to either construct a link or your preferred substitute if it fails validation.
HTH,
Chuck
^ permalink raw reply [flat|nested] 11+ messages in thread
* Feature request: Allow export to convert broken links to plain text
@ 2019-01-05 20:57 Ryan Thompson
0 siblings, 0 replies; 11+ messages in thread
From: Ryan Thompson @ 2019-01-05 20:57 UTC (permalink / raw)
To: Org-Mode List
[-- Attachment #1: Type: text/plain, Size: 910 bytes --]
Hi all,
I have a use case where I'd like for Org Mode to remove broken links while
preserving their text when exporting. In particular, I'm exporting the same
file multiple times with different sets of headlines excluded each time,
and as a result I have to be careful of linking to headlines that might not
be present in every export. It would be much easier if such links could
simply be converted back to plain text for that export, while remaining as
a link for any exports that *do* include the target headline. None of the
existing settings do quite what I want. The "mark" option comes closest. I
basically want "mark" but without adding any additional text around the
link's text. Would the developers be willing to merge such a feature if I
wrote it? I would add another possible value to
"org-export-with-broken-links", perhaps calling it something like "unlink"
or "strip".
Thanks,
Ryan Thompson
[-- Attachment #2: Type: text/html, Size: 1066 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-09-11 17:13 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-13 22:55 Feature request: Allow export to convert broken links to plain text Janek Fischer
2023-04-15 6:50 ` Hanno Perrey
2023-04-17 13:56 ` Ihor Radchenko
-- strict thread matches above, loose matches on Subject: below --
2019-01-12 20:38 Ryan Thompson
2019-01-12 20:42 ` Ryan Thompson
2019-01-13 17:50 ` Berry, Charles
2019-01-13 21:33 ` Ryan Thompson
2019-01-13 22:34 ` Berry, Charles
2023-09-10 4:13 ` Ryan C. Thompson
2023-09-11 17:12 ` Berry, Charles
2019-01-05 20:57 Ryan Thompson
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).