weituotian / md_numbered_headers

sublime text3 plugin for markdown, auto insert/update/remove header numbers
Apache License 2.0
9 stars 1 forks source link

Number at start of header breaks auto-numbering #2

Open kmarchand opened 6 years ago

kmarchand commented 6 years ago

Great plugin, really useful!

I noticed that if the heading starts with an integer the automated numbering breaks when the plugin is run. If there is any text before a number in the heading it looks to be ok.

Example;

Initial text:

# First Heading Test
## Second Heading Test
### Third Heading Test
# 1 First Heading Test with number at start
## 2 Second Heading Test with number at start
### 3 Third Heading Test with number at start
# First Heading Test with number at end 1
## Second Heading Test with number at end 2
### Third Heading Test with number at end 3

After running plugin:

# 1. First Heading Test
## 1.1. Second Heading Test
### 1.1.1. Third Heading Test
# 2.First Heading Test with number at start
## 2.1.Second Heading Test with number at start
### 2.1.1.Third Heading Test with number at start
# 3. First Heading Test with number at end 1
## 3.1. Second Heading Test with number at end 2
### 3.1.1. Third Heading Test with number at end 3

As you can see the middle section with integers at the start cause a problem.

This came up when I had a heading for video standards:

## 1080p - blah blah blah Which turns into;

## 1.p - blah blah blah Unless I have it start with text like this;

## Text 1080p - blah blah blah In which case it's ok;

## 1. Text 1080p - blah blah blah

I can see the difficulty where you need to update the headings and have to determine which integer is part of the auto-numbering vs part of the text... maybe add a warning when first inserting the numbering if it finds any headings that start with an integer?

weituotian commented 6 years ago

thanks for your great feedback!!! I am trying to find a solution the solve this problem.

and i think i should update the pattern to match the correct heading.

weituotian commented 6 years ago

this commit may fix your issue, i had update the regex to detect the numbered headers . you can follow guide to install the latest version.