build(aio): do not auto-link code elements already inside a link (#18776)

Closes #18769

PR Close #18776
This commit is contained in:
Peter Bacon Darwin
2017-08-18 14:48:40 +01:00
committed by Miško Hevery
parent 7d72d0eb9b
commit b8a3736275
4 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,4 @@
const visit = require('unist-util-visit');
const visit = require('unist-util-visit-parents');
const is = require('hast-util-is-element');
const textContent = require('hast-util-to-string');
@ -17,8 +17,8 @@ module.exports = function autoLinkCode(getDocFromAlias) {
function autoLinkCodeImpl() {
return (ast) => {
visit(ast, node => {
if (is(node, 'code')) {
visit(ast, (node, ancestors) => {
if (is(node, 'code') && ancestors.every(ancestor => !is(ancestor, 'a'))) {
const docs = getDocFromAlias(textContent(node));
if (docs.length === 1 && autoLinkCodeImpl.docTypes.indexOf(docs[0].docType) !== -1) {
const link = {