tajmone / pandoc-goodies

A tresure-box of resources for pandoc, pp and Texts word processor.
MIT License
211 stars 41 forks source link

Support relative page header links #7

Closed rattletat closed 5 years ago

rattletat commented 5 years ago

Relative page links like https://github.com/tajmone/pandoc-goodies/tree/master/templates/html5/github#primer-css or https://github.com/tajmone/pandoc-goodies#gnu-general-public-license would be awesome.

tajmone commented 5 years ago

I'm not sure I understand, where are these supposed be available? in the GitHub previews of the documentation?

tajmone commented 5 years ago

You mean like this?

rattletat commented 5 years ago

Exactly. I use a local website generated with pandoc. Atleast file links like file:///home/user/site/index.html#Notes do not jump to their respectice header and links like file:///home/user/site/exercises#Exercise%20II..html do not work at all. The last one is generated when following a link. Also, with linked local files (i.e. pdfs) it is always a .html attached, resulting in file.pdf.html, but this could be a pandoc config thing.

tajmone commented 5 years ago

Pandoc has some options to control how the headings anchor IDs in the final document are generated, and these will always be linkable. I don't remember the various options out of my head (I'll look them up), but you should be able to look at the generated HTML source and extract those anchors.

You should also be careful about case-sensitiveness, for usually anchors are converted to lowercase.

Let me check Pandoc docs and I'll be back with some options discussion...

tajmone commented 5 years ago

http://pandoc.org/MANUAL.html#extension-auto_identifiers

http://pandoc.org/MANUAL.html#heading-identifiers

rattletat commented 5 years ago

Thanks I'll look into it!

tajmone commented 5 years ago

There are various options regarding the algorithms used to produce a valid anchor.

What I find strange is that it doesn't mention the HTML output for those extensions, but I know as a fact that it supports it.

If you tell pandoc to autogenerate a TOC for the html docs/web-pages you can easily test how these links work.

Let me know if you managed to solve it.

rattletat commented 5 years ago

Hi, thanks for your help again! I managed to use the header identifiers. I initally used vimwikis nameing convention, which does not work with pandoc. Maybe I will look into writing a converter, for now I just look the identifer up or just write simpler headers :laughing:

The .html problem was fixed by writing a filter. Mine is

sed 's/\(jpg\|pdf\).html/\1/g' | sed -e 's/\(href=".*\)\.html/\1/g'