]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13343 Fix table of content jump
authorMathieu Suen <mathieu.suen@sonarsource.com>
Wed, 6 May 2020 14:32:53 +0000 (16:32 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 12 May 2020 20:03:55 +0000 (20:03 +0000)
server/sonar-web/package.json
server/sonar-web/src/main/js/@types/rehype-slug.d.ts [new file with mode: 0644]
server/sonar-web/src/main/js/@types/remark-slug.d.ts [deleted file]
server/sonar-web/src/main/js/components/docs/DocMarkdownBlock.tsx
server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx
server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocMarkdownBlock-test.tsx.snap
server/sonar-web/src/main/js/components/docs/plugins/remark-only-toc.js
server/sonar-web/yarn.lock

index b9189e323ac654661709120eca2ef9ade54457ae..f7b0ff36cf83fabd5cf137566bc10e23a150a682 100644 (file)
@@ -35,9 +35,9 @@
     "regenerator-runtime": "0.13.5",
     "rehype-raw": "4.0.2",
     "rehype-react": "5.0.0",
+    "rehype-slug": "3.0.0",
     "remark-custom-blocks": "2.5.0",
     "remark-rehype": "6.0.0",
-    "remark-slug": "5.1.2",
     "sonar-ui-common": "0.0.58",
     "unist-util-visit": "2.0.2",
     "valid-url": "1.0.9",
diff --git a/server/sonar-web/src/main/js/@types/rehype-slug.d.ts b/server/sonar-web/src/main/js/@types/rehype-slug.d.ts
new file mode 100644 (file)
index 0000000..23995cc
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+declare module 'rehype-slug' {
+  export default function rehypeSlug(): any;
+}
diff --git a/server/sonar-web/src/main/js/@types/remark-slug.d.ts b/server/sonar-web/src/main/js/@types/remark-slug.d.ts
deleted file mode 100644 (file)
index 542fb8b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-declare module 'remark-slug' {
-  export default function slug(): any;
-}
index 63aa24978adbc2d54e8890b51ad1f2960530cdce..2ef16eadd6f3f54b83965084ef99703d18804c32 100644 (file)
@@ -21,10 +21,10 @@ import * as classNames from 'classnames';
 import * as React from 'react';
 import rehypeRaw from 'rehype-raw';
 import rehypeReact from 'rehype-react';
+import rehypeSlug from 'rehype-slug';
 import remark from 'remark';
 import remarkCustomBlocks from 'remark-custom-blocks';
 import remarkRehype from 'remark-rehype';
-import slug from 'remark-slug';
 import MetaData from 'sonar-ui-common/components/ui/update-center/MetaData';
 import { scrollToElement } from 'sonar-ui-common/helpers/scrolling';
 import DocCollapsibleBlock from './DocCollapsibleBlock';
@@ -73,6 +73,7 @@ export default class DocMarkdownBlock extends React.PureComponent<Props> {
       collapse: { classes: 'collapse' }
     })
       .use(remarkRehype, { allowDangerousHTML: true })
+      .use(rehypeSlug)
       .use(rehypeRaw)
       .use(rehypeReact, {
         createElement: React.createElement,
@@ -88,8 +89,7 @@ export default class DocMarkdownBlock extends React.PureComponent<Props> {
             <MetaData updateCenterKey={updatecenterkey} />
           )
         }
-      })
-      .use(slug);
+      });
 
     return (
       <div
index 31baaaaae3da802ba8e116e5c983fc0c46fbb3e8..ab956302584655a64be4f7e6356e07956886b12c 100644 (file)
@@ -47,7 +47,7 @@ jest.mock('remark', () => ({ default: jest.requireActual('remark') }));
 jest.mock('remark-rehype', () => ({ default: jest.requireActual('remark-rehype') }));
 jest.mock('rehype-raw', () => ({ default: jest.requireActual('rehype-raw') }));
 jest.mock('rehype-react', () => ({ default: jest.requireActual('rehype-react') }));
-jest.mock('remark-slug', () => ({ default: jest.requireActual('remark-slug') }));
+jest.mock('rehype-slug', () => ({ default: jest.requireActual('rehype-slug') }));
 
 jest.mock('../../../helpers/system', () => ({
   getInstance: jest.fn(),
index 9a3ab8251473fdbe92ea3a98543547ce184c17fd..6e98ebcc68b9933b4ad4dc8e892357d02611c152 100644 (file)
@@ -12,6 +12,7 @@ exports[`should render a sticky TOC if available 1`] = `
         key="h-1"
       >
         <h2
+          id="lorem-ipsum"
           key="h-2"
         >
           Lorem ipsum
@@ -26,6 +27,7 @@ exports[`should render a sticky TOC if available 1`] = `
         
 
         <h2
+          id="sit-amet"
           key="h-4"
         >
           Sit amet
@@ -33,6 +35,7 @@ exports[`should render a sticky TOC if available 1`] = `
         
 
         <h3
+          id="maecenas-diam"
           key="h-5"
         >
           Maecenas diam
@@ -47,6 +50,7 @@ exports[`should render a sticky TOC if available 1`] = `
         
 
         <h3
+          id="integer"
           key="h-7"
         >
           Integer
@@ -61,6 +65,7 @@ exports[`should render a sticky TOC if available 1`] = `
         
 
         <h2
+          id="nam-blandit"
           key="h-9"
         >
           Nam blandit
index 3aa0531336321aaf8135aa8683fef1e8483d230e..a950de2098bfbd2ada16f8e1ebdb4d569e2401e2 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import util from 'mdast-util-toc';
-import slug from 'remark-slug';
-
 /**
  * This is a simplified version of the remark-toc plugin: https://github.com/remarkjs/remark-toc
  * It *only* renders the TOC, and leaves all the rest out.
  */
 export default function onlyToc() {
-  this.use(slug);
-
   return transformer;
 
   function transformer(node) {
index df6e99dae7079d2570ed9ea799d1da69ae152081..6e8efae570af59d7a01bb856dd16c83da011cf29 100644 (file)
@@ -5223,14 +5223,7 @@ getpass@^0.1.1:
   dependencies:
     assert-plus "^1.0.0"
 
-github-slugger@^1.0.0:
-  version "1.2.1"
-  resolved "https://repox.jfrog.io/repox/api/npm/npm/github-slugger/-/github-slugger-1.2.1.tgz#47e904e70bf2dccd0014748142d31126cfd49508"
-  integrity sha1-R+kE5wvy3M0AFHSBQtMRJs/UlQg=
-  dependencies:
-    emoji-regex ">=6.0.0 <=6.1.1"
-
-github-slugger@^1.2.1:
+github-slugger@^1.1.1, github-slugger@^1.2.1:
   version "1.3.0"
   resolved "https://repox.jfrog.io/repox/api/npm/npm/github-slugger/-/github-slugger-1.3.0.tgz#9bd0a95c5efdfc46005e82a906ef8e2a059124c9"
   integrity sha1-m9CpXF79/EYAXoKpBu+OKgWRJMk=
@@ -5519,6 +5512,16 @@ hast-util-from-parse5@^5.0.0:
     web-namespaces "^1.1.2"
     xtend "^4.0.1"
 
+hast-util-has-property@^1.0.0:
+  version "1.0.4"
+  resolved "https://registry.yarnpkg.com/hast-util-has-property/-/hast-util-has-property-1.0.4.tgz#9f137565fad6082524b382c1e7d7d33ca5059f36"
+  integrity sha512-ghHup2voGfgFoHMGnaLHOjbYFACKrRh9KFttdCzMCbFoBMJXiNi2+XTrPP8+q6cDJM/RSqlCfVWrjp1H201rZg==
+
+hast-util-is-element@^1.0.0:
+  version "1.0.4"
+  resolved "https://registry.yarnpkg.com/hast-util-is-element/-/hast-util-is-element-1.0.4.tgz#059090a05cc02e275df1ad02caf8cb422fcd2e02"
+  integrity sha512-NFR6ljJRvDcyPP5SbV7MyPBgF47X3BsskLnmw1U34yL+X6YC0MoBx9EyMg8Jtx4FzGH95jw8+c1VPLHaRA0wDQ==
+
 hast-util-parse-selector@^2.0.0:
   version "2.2.4"
   resolved "https://repox.jfrog.io/repox/api/npm/npm/hast-util-parse-selector/-/hast-util-parse-selector-2.2.4.tgz#60c99d0b519e12ab4ed32e58f150ec3f61ed1974"
@@ -5556,6 +5559,11 @@ hast-util-to-parse5@^5.0.0:
     xtend "^4.0.0"
     zwitch "^1.0.0"
 
+hast-util-to-string@^1.0.0:
+  version "1.0.3"
+  resolved "https://registry.yarnpkg.com/hast-util-to-string/-/hast-util-to-string-1.0.3.tgz#897d4bbd0dc7a9b0765a943a82fa38136277de1f"
+  integrity sha512-3lDgDE5OdpTfP3aFeKRWEwdIZ4vprztvp+AoD+RhF7uGOBs1yBDWZFadxnjcUV4KCoI3vB9A7gdFO98hEXA90w==
+
 hastscript@^5.0.0:
   version "5.1.2"
   resolved "https://repox.jfrog.io/repox/api/npm/npm/hastscript/-/hastscript-5.1.2.tgz#bde2c2e56d04c62dd24e8c5df288d050a355fb8a"
@@ -7479,11 +7487,6 @@ mdast-util-to-hast@^8.0.0:
     unist-util-position "^3.0.0"
     unist-util-visit "^2.0.0"
 
-mdast-util-to-string@^1.0.0:
-  version "1.0.6"
-  resolved "https://repox.jfrog.io/repox/api/npm/npm/mdast-util-to-string/-/mdast-util-to-string-1.0.6.tgz#7d85421021343b33de1552fc71cb8e5b4ae7536d"
-  integrity sha1-fYVCECE0OzPeFVL8ccuOW0rnU20=
-
 mdast-util-to-string@^1.0.5:
   version "1.1.0"
   resolved "https://repox.jfrog.io/repox/api/npm/npm/mdast-util-to-string/-/mdast-util-to-string-1.1.0.tgz#27055500103f51637bd07d01da01eb1967a43527"
@@ -9778,6 +9781,17 @@ rehype-react@5.0.0:
     "@mapbox/hast-util-table-cell-style" "^0.1.3"
     hast-to-hyperscript "^8.0.0"
 
+rehype-slug@3.0.0:
+  version "3.0.0"
+  resolved "https://registry.yarnpkg.com/rehype-slug/-/rehype-slug-3.0.0.tgz#8416257df9665981894a1f0cd42b13c407bbcc8e"
+  integrity sha512-zFnj5BCEJXV6+URwaz8yW+9BdjDwO5iVzlQui3+7cCJ9MXlIEL0IY8VefcT/03Gw+2Hutdrx+zXnS7bnOrepZg==
+  dependencies:
+    github-slugger "^1.1.1"
+    hast-util-has-property "^1.0.0"
+    hast-util-is-element "^1.0.0"
+    hast-util-to-string "^1.0.0"
+    unist-util-visit "^2.0.0"
+
 relateurl@0.2.x:
   version "0.2.7"
   resolved "https://repox.jfrog.io/repox/api/npm/npm/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9"
@@ -9828,15 +9842,6 @@ remark-rehype@6.0.0:
   dependencies:
     mdast-util-to-hast "^8.0.0"
 
-remark-slug@5.1.2:
-  version "5.1.2"
-  resolved "https://repox.jfrog.io/repox/api/npm/npm/remark-slug/-/remark-slug-5.1.2.tgz#715ecdef8df1226786204b1887d31ab16aa24609"
-  integrity sha1-cV7N743xImeGIEsYh9MasWqiRgk=
-  dependencies:
-    github-slugger "^1.0.0"
-    mdast-util-to-string "^1.0.0"
-    unist-util-visit "^1.0.0"
-
 remark-stringify@^7.0.0:
   version "7.0.4"
   resolved "https://repox.jfrog.io/repox/api/npm/npm/remark-stringify/-/remark-stringify-7.0.4.tgz#3de1e3f93853288d3407da1cd44f2212321dd548"