-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a simple way to customize anchor injection #75
base: main
Are you sure you want to change the base?
Conversation
e3d1091
to
d68bb90
Compare
d68bb90
to
02c24ea
Compare
|
||
```liquid | ||
<!-- Append an anchor pilcrow after the heading text, Sphinx style: --> | ||
{{ heading_text }} <a class="anchor" aria-hidden="true" href="{{ page.url }}{{ heading_id }}">¶</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering why you need to configure page.url
.
I think anchor's href
should be #heading-title
, for instance. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this example, the idea is for the anchor to provide an absolute reference so right click -> copy link gives something which can be pasted anywhere. Of course, the goal is for customization; you could of course just use #{{ heading_id }}
to get a relative reference, if that is what one wishes.
@gandalf3 How do you think about using anchor.js? Does this meet your requirement? |
@toshimaru I was also looking for a way to do this in jekyll to avoid (imo unnecessary) javascript. That said I understand if most are happy with a javascript solution, and I can live with using my patched version for my own purposes if you decide this feature doesn't fit in jekyll-toc. |
Implementation for #43
This change adds a setting for a liquid template to be used for anchor injection:
The template is supplied with the original text content (
heading_text
) and id (heading_id
) for each heading element:The above template, when injected on an
<h1>
, yields html like the following: