ppoffice / hexo-component-inferno

A collection of Inferno.js layout components and utility scripts for Hexo
https://ppoffice.github.io/hexo-component-inferno/
24 stars 30 forks source link

Generate Wrong TOC #59

Closed ppwwyyxx closed 8 months ago

ppwwyyxx commented 1 year ago

I have a post with the following headings (there is no h3):

h2
h2
h2
h4
h4
h4
h4
h2

And I used the toc widget with depth=3. I printed tocObj from https://github.com/ppoffice/hexo-component-inferno/blob/fa580355c039fdbfbb66f9bd7bd298a56af575ab/src/view/widget/toc.jsx#L50 and it shows

[
  { text: 'Registration', id: 'Registration', level: 2 },
  {
    text: 'Pay for what you use',
    id: 'Pay-for-what-you-use',
    level: 2
  },
  { text: 'Global states', id: 'Global-states', level: 2 },
  { text: 'Name conflicts', id: 'Name-conflicts', level: 4 },
  { text: 'Overwrites', id: 'Overwrites', level: 4 },
  {
    text: 'Pickle & multiprocessing',
    id: 'Pickle-multiprocessing',
    level: 4
  },
  { text: 'Obscure Provenance', id: 'Obscure-Provenance', level: 4 },
  {
    text: 'Alternative: just use full qualname',
    id: 'Alternative-just-use-full-qualname',
    level: 2
  }
]

However, when I print the return value of the getToc function, it's:

{
  '1': { id: 'Registration', text: 'Registration', index: '1' },
  '2': {
    id: 'Pay-for-what-you-use',
    text: 'Pay for what you use',
    index: '2'
  },
  '3': {
    '1': {
      id: 'Obscure-Provenance',
      text: 'Obscure Provenance',
      index: '3.1'
    },
    id: 'Global-states',
    text: 'Global states',
    index: '3'
  },
  '4': {
    id: 'Alternative-just-use-full-qualname',
    text: 'Alternative: just use full qualname',
    index: '4'
  }
}

So among the 4 h4s, only one is kept.

I don't know what the intended behavior is (keep all h4? keep no h4? throw an error?), but the current behavior is probably not intended.

ppoffice commented 1 year ago

The ToC should now generate correct headings with the latest commit.

## title 0
## title 1
#### title 2
#### title 3
#### title 4
## title 5

image