From d6143868a46c712b9d3fb5bb70127a00d7169629 Mon Sep 17 00:00:00 2001
From: Endi <Head />
',
+ id: 'head-',
+ children: [
+ {
+ value: '<Head>Test</Head>
',
+ id: 'headtesthead',
+ children: []
+ }
+ ]
+ },
+ {
+ value: '<div />
',
+ id: 'div-',
+ children: []
+ },
+ {
+ value: '<div> Test </div>
',
+ id: 'div-test-div',
+ children: []
+ },
+ {
+ value: '<div><i>Test</i></div>
',
+ id: 'divitestidiv',
+ children: []
+ }
+];
+
+## \`
` + +### `
Test` + +## `
` + +## `
` + +## `
`
\ No newline at end of file
diff --git a/packages/docusaurus-mdx-loader/src/remark/rightToc/__tests__/index.test.js b/packages/docusaurus-mdx-loader/src/remark/rightToc/__tests__/index.test.js
index 9535ad1564..2031e2c8b7 100644
--- a/packages/docusaurus-mdx-loader/src/remark/rightToc/__tests__/index.test.js
+++ b/packages/docusaurus-mdx-loader/src/remark/rightToc/__tests__/index.test.js
@@ -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(`
diff --git a/packages/docusaurus-mdx-loader/src/remark/rightToc/search.js b/packages/docusaurus-mdx-loader/src/remark/rightToc/search.js
index b8d36029ea..400530a62b 100644
--- a/packages/docusaurus-mdx-loader/src/remark/rightToc/search.js
+++ b/packages/docusaurus-mdx-loader/src/remark/rightToc/search.js
@@ -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 `${node.value}
`;
+ return `${escapeHtml(node.value)}
`;
case 'emphasis':
return `${node.children.map(toValue).join('')}`;
case 'strong':
diff --git a/yarn.lock b/yarn.lock
index c4855e2c11..1e54ecd96f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -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=