snosov1 / toc-org

toc-org is an Emacs utility to have an up-to-date table of contents in the org files without exporting (useful primarily for readme files on GitHub)
GNU General Public License v3.0
292 stars 29 forks source link

Bug: can't resolve link in TOC when exporting to html #35

Closed deb0ch closed 7 years ago

deb0ch commented 7 years ago

I've been experiencing a bug lately when having a table of contents declared as :TOC: and then trying to export to html. The error is Unable to resolve link: <name-of-your-first-heading>.

Here is a minimal example:

* toc :TOC:
 - [[#foo][foo]]
 - [[#bar][bar]]
 - [[#baz][baz]]

* foo
Aliquam erat volutpat. Nunc eleifend leo vitae magna. In id erat non orci
commodo lobortis. Proin neque massa, cursus ut, gravida ut, lobortis eget,
lacus. Sed diam. Praesent fermentum tempor tellus.

* bar
Nullam eu ante vel est convallis dignissim. Fusce suscipit, wisi nec facilisis
facilisis, est dui fermentum leo, quis tempor ligula erat quis odio. Nunc porta
vulputate tellus. Nunc rutrum turpis sed pede. Sed bibendum.

* baz
Nullam eu ante vel est convallis dignissim. Fusce suscipit, wisi nec facilisis
facilisis, est dui fermentum leo, quis tempor ligula erat quis odio. Nunc porta
vulputate tellus. Nunc rutrum turpis sed pede. Sed bibendum.

then when trying export to html (M-x org-export-dispatch RET h o for instance), you get the error user-error: Unable to resolve link: "foo" in *Messages* and just Unable to resolve link: "foo" in the echo area.

A simple workaround is to declare the toc as :TOC:noexport:. This way you don't get the error and the toc is still exported, it just doesn't make sense given what :noexport: is supposed to do :confused:

snosov1 commented 7 years ago

Hey, @deb0ch !

Thx for the report.

First, please, let me put your mind into the right place with respect to :noexport: tag. Probably, the thing is - after you add :noexport: the toc is being generated by the org-html export. So, it's not a bug and it's not related to this package =) Simple way to test it is to add #+OPTIONS: toc:nil to the top of your file.

Next, to the bug with Unable to resolve link. I can also reproduce this, but it doesn't seem like a bug to me. Obviously, you use the "github-style" href format for links but then export to html (that uses a different href format) which causes issues.

There are several options to handle this:

Does it make any sense?

snosov1 commented 7 years ago

Closing as "Not a bug".

MatthewZMD commented 5 years ago

To enable it, simply use :TOC_2_org:

I tried this, most things worked out nicely. However the generated table of contents has the :TOC_2_org: in it, which doesn't look very good.

snosov1 commented 5 years ago

@MatthewZMD True. Unfortunately, I'm not sure what's the cleanest way to get around it.

You can kinda make it better by adding smth like #+HTML_HEAD_EXTRA: <style> .TOC_2_org { display: none; } </style>. Though it still leaves the tag span and adds clutter to the source file.