From 6437cf0f862a18f4d1f16d5c84d8e9df1d0141a6 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Sun, 2 Oct 2022 16:51:47 +0200 Subject: [PATCH] resolves #209 open xref from preview - set `:relfilesuffix: .adoc` by default on preview - set data-href on xref links --- src/asciidocParser.ts | 1 + src/asciidoctorWebViewConverter.ts | 31 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/asciidocParser.ts b/src/asciidocParser.ts index 5ea04699..f449d941 100644 --- a/src/asciidocParser.ts +++ b/src/asciidocParser.ts @@ -158,6 +158,7 @@ export class AsciidocParser { }) attributes['env-vscode'] = '' attributes.env = 'vscode' + attributes['relfilesuffix@'] = '.adoc' const baseDir = AsciidocParser.getBaseDir(doc.fileName) const templateDirs = this.getTemplateDirs() diff --git a/src/asciidoctorWebViewConverter.ts b/src/asciidoctorWebViewConverter.ts index 78a79914..237475d3 100644 --- a/src/asciidoctorWebViewConverter.ts +++ b/src/asciidoctorWebViewConverter.ts @@ -180,12 +180,31 @@ export class AsciidoctorWebViewConverter { ` } - if (nodeName === 'inline_anchor' && node.type === 'link') { - const href = isSchemeBlacklisted(node.target) ? '#' : node.target - const id = node.hasAttribute('id') ? ` id="${node.id}"` : '' - const role = node.hasAttribute('role') ? ` class="${node.role}"` : '' - const title = node.hasAttribute('title') ? ` title="${node.title}"` : '' - return `${node.text}` + if (nodeName === 'inline_anchor') { + if (node.type === 'link') { + const href = isSchemeBlacklisted(node.target) ? '#' : node.target + const id = node.hasAttribute('id') ? ` id="${node.id}"` : '' + const role = node.hasAttribute('role') ? ` class="${node.role}"` : '' + const title = node.hasAttribute('title') ? ` title="${node.title}"` : '' + return `${node.text}` + } + if (node.type === 'xref') { + const path = node.getAttributes().path + let text + if (path) { + text = node.getText() || path + } else { + text = node.getText() + if (text) { + // noop + } else { + // todo: resolve xref text + text = `[${node.getAttributes().refid}]` + } + } + const role = node.hasAttribute('role') ? ` class="${node.role}"` : '' + return `${text}` + } } return this.baseConverter.convert(node, transform) }