vuepress icon indicating copy to clipboard operation
vuepress copied to clipboard

Not able to choose h1 for sidebar

Open Soitora opened this issue 5 years ago • 4 comments

  • [x] I confirm that this is an issue rather than a question.

Bug report

Steps to reproduce

Put sidebarDepth=2, add h1 to markdown extractHeaders

What is expected?

H1 headers to show up in the sidebar

What is actually happening?

Only H2 and H3 headers show up

Other relevant information

I'm honestly not sure if it's just me missing a very essential piece of information, but I've looked for what feels like days, I've honestly not found anything unless it's so plainly in sight it makes me blind to it.

This is relevant for https://github.com/Soitora/tachiyomi-website/tree/mergeFaq, specifically for /src/help/faq/README.md

  • Output of npx vuepress info in my VuePress project:

Environment Info:

System: OS: Windows 10 10.0.18363 CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz Binaries: Node: 12.16.1 - D:\NodeJS\node.EXE Yarn: 1.22.4 - D:\Yarn\bin\yarn.CMD npm: 6.13.4 - D:\NodeJS\npm.CMD Browsers: Edge: 44.18362.449.0 npmPackages: @vuepress/core: 1.4.1 @vuepress/theme-default: 1.4.1 vuepress: ^1.4.1 => 1.4.1 npmGlobalPackages: vuepress: Not Found

Soitora avatar Apr 28 '20 00:04 Soitora

Okay so I just changed all H1 to H2, H2 to H3 etc. But it would still be nice having H1 available

Soitora avatar Apr 30 '20 03:04 Soitora

Same issue here. Any further information on how to get H1s, beside the first one, to show up in the sidebar?

dhust avatar Nov 14 '21 20:11 dhust

Here is my workaround to render all H1 title (markdown contain multi # title). Maybe the best way is to customize a theme.

// file: node_modules/@vuepress/core/lib/node/Page.js 
// line49

extractHeaders = ['h1','h2', 'h3']
// file: node_modules/@vuepress/theme-default/util/index.js 
// line171 - line183

export function groupHeaders (headers) {
  // group h3s under h2
  headers = headers.map(h => Object.assign({}, h))
  let topLevel = 2;//There is only one H1 by default
  let h1List = headers.filter(h => h.level === 1)
  if (h1List.length > 1) {
    topLevel = 1;
  }
  let lastH2
  headers.forEach(h => {
    if (h.level === topLevel) {
      lastH2 = h
    } else if (lastH2) {
      (lastH2.children || (lastH2.children = [])).push(h)
    }
  })
  return headers.filter(h => h.level === topLevel)
}

Panway avatar Jan 23 '22 13:01 Panway

I'm also experiencing this issue. Any chance someone can get this patched?

dkattan avatar Feb 10 '22 16:02 dkattan