6

When exporting, links are converted to the relevant format. Is it possible to tell org to simply ignore links and only export their text? (that is, completely ignoring the link, not including it as plain text)

My case is for exporting to Markdown, but I believe a solution should apply to all export back-ends.

1 Answer 1

4

If there were a general org export option to do so I would expect to see it documented here: http://orgmode.org/manual/Export-settings.html#Export-settings. Looking directly at the source I don't see an option in the markdown export engine to do so either. Some options:

Quick-and-Dirty Solution™

If you are looking for the Quick-and-Dirty Solution™. You can redefine the org-md-link function. The function can be trivially simple:

(defun my-org-md-link (link contents info) contents)

If that breaks something else in your output (unlikely) you can at the very least directly revise the output formatting lines like

(format "[%s](%s)" contents path)

with

(format "%s" contents path)

If you want to preserve the original behavior of the export engine in some circumstances you can register a derived export engine:

(org-export-define-derived-backend 'my-md 'md
    :menu-entry
     '(?M "Export to Markdown without links" (lambda (a s v b) (org-md-export-to-markdown a s v)))
    :translate-alist '((link . my-org-md-link)))

Add a filter which removes the links generated by ox-md (both better and worse)

The org export engine does have a mechanism that allows you a degree of flexibility to control the output of an export. See Filter Markup and Advanced Configuration.

(defun custom-md-link-filter (link backend info)
  "Rewrite markdown links in export to preserve link text only."
  (if (eq backend 'md)
      (replace-regexp-in-string "\\[\\([^]]*\\)\\]([^)]*)" "\\1" link)
    link)
(add-to-list 'org-export-filter-link-functions
              'custom-md-link-filter)

I agree with you; a potential general org export option would be useful and would appropriately belong in the core export engine, so the translator of the selected export engine wouldn't even get called. Kudos to you if you submit a feature request (I would +1 that). If you do submit one-- post a link here for others to track it

2
  • Well, it took me some time to try it... I use the filter solution with #+BIND to make it local.
    – amirdeq
    Commented Jul 10, 2016 at 15:21
  • 1
    amirdeq... could you expand on how you used the solution in a local fashion? (a MWE would be great)
    – SaMeji
    Commented Feb 7, 2023 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.