Closed VladimirAlexiev closed 7 years ago
As I said, I don't really have the motivation to work on this myself. But it looks like you can do this yourself with a little effort. It looks like, the only thing you need to do is to implement a function, like toc-org-hrefify-orghtml
, similar to toc-org-hrefify-gh
that converts text to "href ids". I.e. for github it downcases everything, replaces spaces with -, etc.
But it'll work only in Github, not in org nor HTML? Posted a message to 'emacs-orgmode@gnu.org' that largely repeats the above, and adds:
So my request is: the HTML export should have an option org-export-anchors-use-title
to generate section anchors from the section title.
Github keeps the section number, and doesn't strip the TODO and statistics-cookies.
So a section headline like 3.2.2 TODO Normalization Problems [3/4]
will get this anchor #322-todo-normalization-problems-34
.
So it's best to include further options about which parts of a headline to use:
org-export-anchors-use-section-numbers
"If org-export-with-section-numbers is also enabled, prepend the section number (without any dashes).
This makes your anchors ugly and less stable, but you need to set this for Github preview compatibility"org-export-anchors-use-todo
"Prepend TODO/DONE keywords, in lowercase, to section anchors.
This makes your anchors ugly and less stable, but you need to set this for Github preview compatibility"org-export-anchors-use-title
"Make section anchors from the words in the section title, converting to lowercase and replacing punctuation with dash.
This makes your anchors stable (title changes less frequently than numbering) and readable. Set this for Github preview compatibility"org-export-anchors-use-statistics-cookies
"Append statistic cookies (e.g. [33%] or [1/3]) to section anchor, replacing punctuation with dash.
This makes your anchors ugly and less stable, but you need to set this for Github preview compatibility"But it'll work only in Github, not in org nor HTML?
You can provide your own function that converts headings to links. In case of GitHub, it downcases everything, replaces spaces, etc. For HTML you can generate hrefs, like #sec3-1
, etc. There's more information at https://github.com/snosov1/toc-org#different-href-styles
On the second thought, you can only make 2 work at once. Either Github-Org or HTML-Org. However, you can, probably, workaround this by setting toc-org-hrefify-default
in a pre-export hook. This is the place where it starts to get hairy, but it seems like it can work =) To repeat myself, personally, I would
rather use native Org utilities for HTML export
I'm doing a little cleanup and I'm inclined to close this issue, since it's really out of scope of the package (but something you can do on your side, if you wish). Please, let me know, if you need any support from my side.
Consider http://vladimiralexiev.github.io/Multisensor/validation.html. The TOC section is made by toc-org. But the links don't work (and are shown in italic: that's how the HTML export marks broken links)
The reason is that the HTML exporter (org-plus-contrib-20150803
ox-html.el
) uses numbered anchors, eg http://vladimiralexiev.github.io/Multisensor/validation.html#sec-3-1. The following are tried in succession to obtain apreferred-id
:The first is manually set CUSTOM_ID property, the second a numbered reference (eg "sec-3-1") and the third an ID that's automatically inserted by org-store-link.
Numbered anchors are bad because they are not stable: if I move the section, the anchor will change. Github makes anchors from the heading text, which in my experience is a lot more stable.
toc-org
generates such links whentoc-org-hrefify-default
is "gh".The newest ox-html.el uses this
You see the second line is changed. It uses org-export-get-reference from ox.el, which uses org-export-new-reference, which "Generates random 7 digits hexadecimal numbers". I don't know if that is stored (which would make it stable), but it's certainly not meaningful to any reader of the HTML file.
I'll try to raise an issue to the
ox-export
developers. They have a mailing list, no tracker, that's why I'm posting this here.