Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

underscore are discarded inside the table of content #43

Open
didierGuieu opened this issue May 8, 2024 · 5 comments
Open

underscore are discarded inside the table of content #43

didierGuieu opened this issue May 8, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@didierGuieu
Copy link

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:

  • Automatic Table Of Contents
  • Custom file explorer sorting
  • Editing Toolbar

Thanks.

@didierGuieu didierGuieu added the bug Something isn't working label May 8, 2024
@johansatge
Copy link
Owner

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
Copy link
Author

what do you use to strip the markdown characters ?

@johansatge
Copy link
Owner

const stripMarkdown = (text) => {
text = text.replaceAll('*', '').replaceAll('_', '').replaceAll('`', '')
text = text.replaceAll('==', '').replaceAll('~~', '')
text = text.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // Strip markdown links
return text
}

@didierGuieu
Copy link
Author

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
Copy link
Author

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants