Skip to content

Commit

Permalink
build(docs-infra): mark code blocks to disable auto-linking (#26675)
Browse files Browse the repository at this point in the history
You can now mark `<code>` blocks with a `no-auto-link` css class
to tell the code auto-linker to ignore this code block.

PR Close #26675
  • Loading branch information
petebacondarwin authored and matsko committed Oct 26, 2018
1 parent 56f44be commit 9ff8155
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -30,7 +30,9 @@ module.exports = function autoLinkCode(getDocFromAlias) {
return (ast) => {
visit(ast, 'element', (node, ancestors) => {
// Only interested in code elements that are not inside links
if (autoLinkCodeImpl.codeElements.some(elementType => is(node, elementType)) &&
if (autoLinkCodeImpl.codeElements.some(elementType =>
is(node, elementType)) &&
(!node.properties.className || node.properties.className.indexOf('no-auto-link') === -1) &&
ancestors.every(ancestor => !is(ancestor, 'a'))) {
visit(node, 'text', (node, ancestors) => {
// Only interested in text nodes that are not inside links
Expand Down
Expand Up @@ -109,4 +109,11 @@ describe('autoLinkCode post-processor', () => {
processor.$process([doc]);
expect(doc.renderedContent).toEqual('<code-example><a href="a/b/myclass" class="code-anchor">MyClass</a></code-example>');
});

it('should ignore code blocks that are marked with a `no-auto-link` class', () => {
aliasMap.addDoc({ docType: 'class', id: 'MyClass', aliases: ['MyClass'], path: 'a/b/myclass' });
const doc = { docType: 'test-doc', renderedContent: '<code class="no-auto-link">MyClass</code>' };
processor.$process([doc]);
expect(doc.renderedContent).toEqual('<code class="no-auto-link">MyClass</code>');
});
});

0 comments on commit 9ff8155

Please sign in to comment.