johansatge / obsidian-automatic-table-of-contents

💠 An Obsidian plugin to create a table of contents in a note, that updates itself when the note changes
MIT License
128 stars 12 forks source link

underscore are discarded inside the table of content #43

Open didierGuieu opened 4 months ago

didierGuieu commented 4 months ago

Hello

When headers contain underscore _, the underscore is removed inside the toc.

image

the toc should keep the underscore that come from the header.

How to reproduce :

test_with_underscore

_test_with_an_other_underscore

Tested on MacOs with obsidian 1.5.12

plugins installed:

Thanks.

johansatge commented 3 months ago

Hi,

this is "expected" in the current implementation because markdown characters (*_ etc) are naively stripped from the link text, as it's not possible to have styles there (see Known issues in the readme)

But there are probably possible improvements, feel free to share methods to strip markdown characters in a more efficient way 🙏

didierGuieu commented 3 months ago

what do you use to strip the markdown characters ?

johansatge commented 3 months ago

https://github.com/johansatge/obsidian-automatic-table-of-contents/blob/f6af9833abe8e001337ef9ddef911bcf722c9be4/main.js#L177-L182

didierGuieu commented 3 months ago

If I clearly understand text is the whole header. Something strange in Obsidian is that all the code are interpreted inside the word except the underscore. Perhaps, we could strip the underscore in a different way by removing them only at the begining or the end of the word. Another solution should be to support the escape code and only remove the escape code and keeping the caracter after. Need some other thoughts about it and how to do it in JS.

didierGuieu commented 3 months ago

Last option but the simpler : Adding an option inside the toc for discarding the MD code or not inside the link. Surely the simpliest solution