Closed Kristinita closed 6 years ago
Hi, @Kristinita
How about to add this setting to your MarkdownTOC.sublime-settings
?
{
"id_replacements": {
"" : ["1. ", "2. ", "3. "]
}
}
this will provide following results
<!-- MarkdownTOC style="ordered" autoanchor="true" bracket="round" autolink="true" -->
1. [1. First header](#first-header)
1. [2. Second header](#second-header)
1. [3. Sasha header](#sasha-header)
<!-- /MarkdownTOC -->
<a name="first-header"></a>
# 1. First header
Any text
<a name="second-header"></a>
# 2. Second header
Any text
<a name="sasha-header"></a>
# 3. Sasha header
Any text
Currently id_replacements
doesn't allow regex patterns, so it's hard to cover all numbers though.
I'm working on it.
Would you agree with my idea?
@naokazuterada , thanks, nice idea!
It will works with headers, for example, # 1.4. Any text
or # 4.14.7. Any text
?
Thanks.
@Kristinita
It's possible if id_replacements
supports regex. But I'm still working on it (as I mentioned). Anyway I will send message here when it has been done.
Hi, @Kristinita
I finally released MarkdownTOC v3.0.0 today. (Please follow the Upgrade Guide for detail because it has Breaking changes) Now I think you can deal with your needs with [new feature] regular expressions in 'id_replacements'.
Add this settings into your User Settings(Packages/User/MarkdownTOC.sublime-settings
).
{
"id_replacements": [
{
"pattern": "^[0-9\\. ]+ ",
"replacement": ""
}
]
}
Then you will get following results.
<!-- MarkdownTOC autolink="true" style="ordered" autoanchor="true" -->
1. [1.4. Any text](#any-text)
1. [4.14.7. Any text](#any-text-1)
<!-- /MarkdownTOC -->
<a id="any-text"></a>
# 1.4. Any text
<a id="any-text-1"></a>
# 4.14.7. Any text
1. Request
It would be nice, if you add an option — remove numbered headers from anchor link.
It would be nice, if anchor to header not change, if different numbers (
\n+\.
) in begin of header.2. Settings
For example, I have
SashaExample.md
file. It content:3. Steps to reproduce
I place my carriage in begin of the file → Ctrl+Shift+P (⌘⇧p for Mac) →
MarkdownTOC: Insert TOC
.4. Actual behavior
I share second header as http://SashaSite.com/SashaExample#2-sasha-header.
5. Expected behavior
6. Justification
For example, I modify my
SashaExample.md
file:I save a file → I get result:
Now link http://SashaSite.com/SashaExample#2-sasha-header will be invalid, http://SashaSite.com/SashaExample#3-sasha-header will be correct. It would be nice, if link http://SashaSite.com/SashaExample#sasha-header will correct in both cases.
Thanks.