Skip to content

Commit 100ab01

Browse files
keeliiQingWei-Li
authored andcommitted
Fix nested toc style issue on sidebar (#595)
1. Remove recursive toc outer tag li 2. remove .sidebar li marginLeft 3. add .sidebar ul marginLeft
1 parent a683e5b commit 100ab01

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

src/core/render/compiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export class Compiler {
302302
html = this.compile(text)
303303
} else {
304304
const tree = this.cacheTree[currentPath] || genTree(this.toc, level)
305-
html = treeTpl(tree, '<ul>')
305+
html = treeTpl(tree, '<ul>{inner}</ul>')
306306
this.cacheTree[currentPath] = tree
307307
}
308308

@@ -331,7 +331,7 @@ export class Compiler {
331331

332332
cacheTree[currentPath] = tree
333333
this.toc = []
334-
return treeTpl(tree, '<ul class="app-sub-sidebar">')
334+
return treeTpl(tree)
335335
}
336336

337337
article(text) {

src/core/render/tpl.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,18 @@ export function cover() {
7878
* @param {String} tpl
7979
* @return {String}
8080
*/
81-
export function tree(toc, tpl = '') {
81+
export function tree(toc, tpl = '<ul class="app-sub-sidebar">{inner}</ul>') {
8282
if (!toc || !toc.length) {
8383
return ''
8484
}
85-
85+
let innerHTML = ''
8686
toc.forEach(node => {
87-
tpl += `<li><a class="section-link" href="${node.slug}">${
88-
node.title
89-
}</a></li>`
87+
innerHTML += `<li><a class="section-link" href="${node.slug}">${node.title}</a></li>`
9088
if (node.children) {
91-
tpl += `<li><ul class="children">${tree(node.children)}</li></ul>`
89+
innerHTML += tree(node.children, tpl)
9290
}
9391
})
94-
95-
return tpl
92+
return tpl.replace('{inner}', innerHTML)
9693
}
9794

9895
export function helper(className, content) {

src/themes/basic/_layout.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ main.hidden
236236
display none
237237

238238
ul
239-
margin 0
239+
margin 0 0 0 15px
240240
padding 0
241241

242242
li > p

src/themes/buble.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $sidebar-width = 16rem
2020
li
2121
list-style none
2222
margin 0
23-
padding 0.2em 0 0.2em 1rem
23+
padding 0.2em 0 0.2em 0
2424

2525
ul li ul
2626
padding 0

src/themes/dark.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ body
1717
color #c8c8c8
1818

1919
li
20-
margin 6px 15px
20+
margin 6px 15px 6px 0
2121

2222
ul li a
2323
color #c8c8c8

src/themes/vue.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ body
1717
color #364149
1818

1919
li
20-
margin 6px 0 6px 15px
20+
margin 6px 0 6px 0
2121

2222
ul li a
2323
color #505d6b

0 commit comments

Comments
 (0)