diff --git a/src/Documentation/Markdown/utils/remark-linker.js b/src/Documentation/Markdown/utils/remark-linker.js index c0b14b2cc4..c140412f00 100644 --- a/src/Documentation/Markdown/utils/remark-linker.js +++ b/src/Documentation/Markdown/utils/remark-linker.js @@ -1,23 +1,36 @@ ;`use strict` import visit from 'unist-util-visit' +import { getItemByPath } from '../../SidebarMenu/helper' function linker() { function transformer(tree) { visit(tree, 'inlineCode', function(node, index, parent) { if (parent.type !== 'link' && /dvc\s+[a-z-.]+/.test(node.value)) { let parts = node.value.split(/\s+/) - let url = '/doc/commands-reference/' + parts[1] + + let tmpUrl = '/doc/commands-reference/' + let url + + if (getItemByPath(tmpUrl + parts[1])) { + url = tmpUrl = tmpUrl + parts[1] + } if (parts.length > 2) { - url += '#' + parts[2] + if (getItemByPath(tmpUrl + parts[2])) { + url += '/' + parts[2] + } else { + url += '#' + parts[2] + } } - parent.children[index] = { - type: 'link', - url: url, - children: [node], - position: node.position + if (url) { + parent.children[index] = { + type: 'link', + url: url, + children: [node], + position: node.position + } } } })