Derek Chen-Becker <[email protected]> writes:

> I dug a little bit into the export code and it looks like the default
> function for formatting TOC entries is `org-export-toc-entry-backend',
> which explicitly states that "...it changes links and radio targets into
> regular text." It does take an optional set of transcoders, so I tried
> changing where it gets called in ox-html.el to pass a custom transcoder for
> links:
>
> @@ -2589,7 +2589,9 @@ INFO is a plist used as a communication channel."
>                          (org-element-property :priority headline)))
>           (text (org-export-data-with-backend
>                  (org-export-get-alt-title headline info)
> -                (org-export-toc-entry-backend 'html)
> +                (org-export-toc-entry-backend 'html
> +                  `(link . ,(lambda (l c i)
> +                              (org-html-link l c i))))
>                  info))
>           (tags (and (eq (plist-get info :with-tags) t)
>                      (org-export-get-tags headline info))))
>
> With some minimal testing this does appear to work, at least with the test
> case I created. I don't know that we want to make a default behavior
> change, so it might be better to provide a defcustom to either control
> HTML-ified links or to allow for a custom format function. There may
> already be one, I'm not that familiar with ox-html.el and didn't have time
> to fully review the file.

There is a reason why the link is replaced by description (or url) by
default. TOC items are themselves links, which generally does not play
well with links inside headings.

For example, consider

#+options: toc:t

* [[https://orgmode.org][org]] Test
* [[file:~/Git/worg/images/icons/info.png]] Test 2
* Test 3
   This is a test

The first TOC item will be messed up.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
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>

Reply via email to