Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Compiler {
this.router = router;
this.cacheTree = {};
this.toc = [];
this.blockquoteDepth = 0;
this.cacheTOC = {};
this.linkTarget = config.externalLinkTarget || '_blank';
this.linkRel =
Expand Down Expand Up @@ -113,9 +114,13 @@ export class Compiler {
}

let media;
if (config.type && (media = compileMedia[config.type])) {
const mediaType = Array.isArray(config.type)
? config.type[0]
: config.type;

if (mediaType && (media = compileMedia[mediaType])) {
embed = media.call(this, href, title);
embed.type = config.type;
embed.type = mediaType;
} else {
let type = 'code';
if (/\.(md|markdown)/.test(href)) {
Expand Down Expand Up @@ -165,7 +170,10 @@ export class Compiler {
router,
compiler: this,
});
origin.blockquoteCompiler = blockquoteCompiler({ renderer });
origin.blockquoteCompiler = blockquoteCompiler({
renderer,
compiler: this,
});
origin.code = highlightCodeCompiler({ renderer });
origin.link = linkCompiler({
renderer,
Expand Down
12 changes: 10 additions & 2 deletions src/core/render/compiler/blockquote.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const blockquoteCompiler = ({ renderer }) =>
export const blockquoteCompiler = ({ renderer, compiler }) =>
(renderer.blockquote = function ({ tokens }) {
let openTag = '<blockquote>';
let closeTag = '</blockquote>';
Expand Down Expand Up @@ -40,6 +40,14 @@ export const blockquoteCompiler = ({ renderer }) =>
}
}

const body = this.parser.parse(tokens);
compiler.blockquoteDepth++;
let body = '';

try {
body = this.parser.parse(tokens);
} finally {
compiler.blockquoteDepth--;
}

return `${openTag}${body}${closeTag}`;
});
5 changes: 4 additions & 1 deletion src/core/render/compiler/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const headingCompiler = ({ renderer, router, compiler }) =>
const slug = slugify(config.id || text);
const url = router.toURL(router.getCurrentPath(), { id: slug });
nextToc.slug = stripUrlExceptId(url);
compiler.toc.push(nextToc);

if (compiler.blockquoteDepth === 0) {
compiler.toc.push(nextToc);
}

// Note: tabindex="-1" allows programmatically focusing on heading
// elements after navigation. This is preferred over focusing on the link
Expand Down
30 changes: 27 additions & 3 deletions test/integration/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe('Test sidebar render toc structure', function () {
},
markdown: {
homepage: `
# Getting started
# Getting started
some thing
## Level1
## Level1
foo
### Level2
### Level2
bar
`,
},
Expand Down Expand Up @@ -118,4 +118,28 @@ describe('Test sidebar render toc structure', function () {
expect(level1_A_tag.textContent).toContain('Level1');
expect(level2_A_tag.textContent).toContain('Level2');
});

test('Render sidebar should ignore headings in blockquote by default', async () => {
await docsifyInit({
config: {
loadSidebar: false,
},
markdown: {
homepage: `
# Normal Title
> # Quoted Title
> #Quoted Title Without Space
## Section Title
`,
},
waitForSelector: '.sidebar-nav > ul',
});

const sidebarText = document.querySelector('.sidebar-nav').textContent;

expect(sidebarText).toContain('Normal Title');
expect(sidebarText).toContain('Section Title');
expect(sidebarText).not.toContain('Quoted Title');
expect(sidebarText).not.toContain('Quoted Title Without Space');
});
});
Loading