mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 00:27:21 +02:00
fix(v1): markdown content and toc should render the same (#2022)
* fix(v1): autogenerated_toc and sidebar toc should render the same * revert test docs * yarn.lock
This commit is contained in:
parent
91902ed709
commit
bd68dce667
4 changed files with 31 additions and 23 deletions
|
@ -7,7 +7,6 @@
|
|||
|
||||
const {Remarkable} = require('remarkable');
|
||||
const mdToc = require('markdown-toc');
|
||||
const striptags = require('striptags');
|
||||
const GithubSlugger = require('github-slugger');
|
||||
const toSlug = require('./toSlug');
|
||||
|
||||
|
@ -27,7 +26,10 @@ function getTOC(content, headingTags = 'h2', subHeadingTags = 'h3') {
|
|||
? [].concat(subHeadingTags).map(tagToLevel)
|
||||
: [];
|
||||
const allowedHeadingLevels = headingLevels.concat(subHeadingLevels);
|
||||
const md = new Remarkable();
|
||||
const md = new Remarkable({
|
||||
// Enable HTML tags in source (same as './renderMarkdown.js')
|
||||
html: true,
|
||||
});
|
||||
const headings = mdToc(content).json;
|
||||
const toc = [];
|
||||
const slugger = new GithubSlugger();
|
||||
|
@ -35,8 +37,7 @@ function getTOC(content, headingTags = 'h2', subHeadingTags = 'h3') {
|
|||
|
||||
headings.forEach(heading => {
|
||||
const rawContent = heading.content;
|
||||
const safeContent = striptags(rawContent);
|
||||
const rendered = md.renderInline(safeContent);
|
||||
const rendered = md.renderInline(rawContent);
|
||||
|
||||
const hashLink = toSlug(rawContent, slugger);
|
||||
if (!allowedHeadingLevels.includes(heading.lvl)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue