mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 10:17:55 +02:00
fix(v2): toc should not be broken for heading with html inline code (#2067)
This commit is contained in:
parent
3b060ad171
commit
d6143868a4
6 changed files with 60 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
|||
"@babel/traverse": "^7.7.4",
|
||||
"@mdx-js/mdx": "^1.5.1",
|
||||
"@mdx-js/react": "^1.5.1",
|
||||
"escape-html": "^1.0.3",
|
||||
"github-slugger": "^1.2.1",
|
||||
"gray-matter": "^4.0.2",
|
||||
"loader-utils": "^1.2.3",
|
||||
|
|
|
@ -1,5 +1,47 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`inline code should be escaped 1`] = `
|
||||
"export const rightToc = [
|
||||
{
|
||||
value: '<code><Head /></code>',
|
||||
id: 'head-',
|
||||
children: [
|
||||
{
|
||||
value: '<code><Head>Test</Head></code>',
|
||||
id: 'headtesthead',
|
||||
children: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
value: '<code><div /></code>',
|
||||
id: 'div-',
|
||||
children: []
|
||||
},
|
||||
{
|
||||
value: '<code><div> Test </div></code>',
|
||||
id: 'div-test-div',
|
||||
children: []
|
||||
},
|
||||
{
|
||||
value: '<code><div><i>Test</i></div></code>',
|
||||
id: 'divitestidiv',
|
||||
children: []
|
||||
}
|
||||
];
|
||||
|
||||
## \`<Head />\`
|
||||
|
||||
### \`<Head>Test</Head>\`
|
||||
|
||||
## \`<div />\`
|
||||
|
||||
## \`<div> Test </div>\`
|
||||
|
||||
## \`<div><i>Test</i></div>\`
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`non text phrasing content 1`] = `
|
||||
"export const rightToc = [
|
||||
{
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
## `<Head />`
|
||||
|
||||
### `<Head>Test</Head>`
|
||||
|
||||
## `<div />`
|
||||
|
||||
## `<div> Test </div>`
|
||||
|
||||
## `<div><i>Test</i></div>`
|
|
@ -27,6 +27,11 @@ test('non text phrasing content', async () => {
|
|||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('inline code should be escaped', async () => {
|
||||
const result = await processFixture('inline-code');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('text content', async () => {
|
||||
const result = await processFixture('just-content');
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
const toString = require('mdast-util-to-string');
|
||||
const visit = require('unist-util-visit');
|
||||
const escapeHtml = require('escape-html');
|
||||
const slugs = require('github-slugger')();
|
||||
|
||||
// https://github.com/syntax-tree/mdast#heading
|
||||
|
@ -18,7 +19,7 @@ function toValue(node) {
|
|||
case 'heading':
|
||||
return node.children.map(toValue).join('');
|
||||
case 'inlineCode':
|
||||
return `<code>${node.value}</code>`;
|
||||
return `<code>${escapeHtml(node.value)}</code>`;
|
||||
case 'emphasis':
|
||||
return `<em>${node.children.map(toValue).join('')}</em>`;
|
||||
case 'strong':
|
||||
|
|
|
@ -5939,7 +5939,7 @@ es6-promisify@^5.0.0:
|
|||
dependencies:
|
||||
es6-promise "^4.0.3"
|
||||
|
||||
escape-html@~1.0.3:
|
||||
escape-html@^1.0.3, escape-html@~1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
|
||||
integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
|
||||
|
|
Loading…
Add table
Reference in a new issue