diff --git a/packages/antora-xref-extension/lib/index.js b/packages/antora-xref-extension/lib/index.js index 4adcc12..a39d38d 100644 --- a/packages/antora-xref-extension/lib/index.js +++ b/packages/antora-xref-extension/lib/index.js @@ -92,21 +92,25 @@ function register ({ config }) { } function processNode (src, node, lookup) { - const context = node.getContext() - if (context === 'paragraph' || context === 'admonition') { - const lines = node.lines - for (let i = 0; i < lines.length; i++) { - lines[i] = processLine(src, node, lines[i], lookup) + try { + const context = node.getContext() + if (context === 'paragraph' || context === 'admonition') { + const lines = node.lines + for (let i = 0; i < lines.length; i++) { + lines[i] = processLine(src, node, lines[i], lookup) + } + } else if (context === 'table') { + const rows = node.getRows() + rows.getHead().forEach((row) => row.forEach((cell) => processNode(src, cell, lookup))) + rows.getBody().forEach((row) => row.forEach((cell) => processNode(src, cell, lookup))) + rows.getFoot().forEach((row) => row.forEach((cell) => processNode(src, cell, lookup))) + } else if (context === 'table_cell' || context === 'list_item') { + node.text = processLine(src, node, node.text, lookup) } - } else if (context === 'table') { - const rows = node.getRows() - rows.getHead().forEach((row) => row.forEach((cell) => processNode(src, cell, lookup))) - rows.getBody().forEach((row) => row.forEach((cell) => processNode(src, cell, lookup))) - rows.getFoot().forEach((row) => row.forEach((cell) => processNode(src, cell, lookup))) - } else if (context === 'table_cell' || context === 'list_item') { - node.text = processLine(src, node, node.text, lookup) + node.getBlocks().forEach((child) => processNode(src, child, lookup)) + } catch (t) { + log(node, 'warn', 'Parse error when validating xrefs. Check e.g. for double colons (\'::\')') } - node.getBlocks().forEach((child) => processNode(src, child, lookup)) } function processLine (src, block, line, lookup) { diff --git a/packages/antora-xref-extension/test/xref-fragments-extension-test.js b/packages/antora-xref-extension/test/xref-fragments-extension-test.js index 4ff02a6..182771e 100644 --- a/packages/antora-xref-extension/test/xref-fragments-extension-test.js +++ b/packages/antora-xref-extension/test/xref-fragments-extension-test.js @@ -664,6 +664,27 @@ describe('xref extension', () => { expect(loggerDestination.messages).to.be.empty() }) + it('should not fail but log a warning on unexpected syntax', () => { + const extensionConfig = { + logUnnecessaryLinkTextWarnings: false, + } + addFile( + 'bad.adoc', + heredoc` + = Bad + + bad:: + ` + ) + run(extensionConfig) + const page = contentCatalog.getPages((candidate) => candidate.path === '/bad.adoc')[0] + expect( + loggerDestination.messages.some( + (message) => message.includes('"level":"warn"') && message.includes('Parse error when validating xrefs.') + ) + ).to.be.true() + }) + function addFile (filename, contents) { contents = Buffer.from(contents) const mediaType = 'text/asciidoc'