xenocrat / chyrp-lite

An ultra-lightweight blogging engine, written in PHP.
https://chyrplite.net/
BSD 3-Clause "New" or "Revised" License
402 stars 42 forks source link

FR: Add permalinks to headings #169

Closed Tagirijus closed 2 years ago

Tagirijus commented 2 years ago

I would find it quite useful, if it would be possible to have permalinks for headings, so that you can link to a specific section of the blog directly. Maybe as an optional setting or so. Maybe this could be achieved with a plugin after all?

I can think of two options: either having a id="HEADING-SLUG" by default in each heading tag, so that it would be possible to technically already link to this heading. Optionally there could be a tiny link-icon next to the heading then to be able to fetch this link as well.

What do you think? (=

xenocrat commented 2 years ago

Hello there,

Can you explain in more detail what you mean by headings? The bundled themes add an ID attribute to each post container so you can use it as an anchor, e.g. #post_1 or #post_123.

Tagirijus commented 2 years ago

Hi there,

sorry for being not clear enough. I was talking about the headings / titles / superscriptions inside a post. You got me an idea though: would it be possible to accomplish my idea within a custom theme?

Just in case it is still not clear enough: When I write a post, I use ## Heading markdown for a heading of a section inside a post. This later gets rendered with a <h2> tag then. Maybe it could be changed so that it would add an id property inside this tag as well, for example. So that it would be <h2 id="Heading"> or so.

I hope it gets more clear now. Sorry for the inconvenience! And thanks for your reply! (=

xenocrat commented 2 years ago

You could do this with a module that responds to the filter "markup_text" and adds an ID to headers found in the text. However if you do this automatically with a module you need to ensure the IDs are unique to avoid clashes.

The simpler solution is to fall back to HTML when you need it. Markdown can be mixed freely with HTML, so when you want to give an ID to a header just write:

<h2 id="foo">My Awesome Header</h2>
Tagirijus commented 2 years ago

Thanks for your reply and the module idea. Good to know that it would be possible. I can understand the unique-ness issue, though!

Regarding HTML inside Markdown: I knew this as well. Still thanks for the info!

I will see if I can come up with a module some day then. Issue is solved for me. (=

Thanks again!