Skip to content

Commit

Permalink
resolves #209 open xref from preview
Browse files Browse the repository at this point in the history
- set `:relfilesuffix: .adoc` by default on preview
- set data-href on xref links
  • Loading branch information
ggrossetie committed Oct 2, 2022
1 parent ec8b78b commit 32f85f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/asciidocParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class AsciidocParser {
}
})
attributes['env-vscode'] = ''
attributes['relfilesuffix@'] = '.adoc'

const baseDir = AsciidocParser.getBaseDir(doc.fileName)
const templateDirs = this.getTemplateDirs()
Expand Down
31 changes: 25 additions & 6 deletions src/asciidoctorWebViewConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,31 @@ export class AsciidoctorWebViewConverter {
</body>
</html>`
}
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 `<a href="${href}"${id}${role}${title} data-href="${href}">${node.text}</a>`
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 `<a href="${href}"${id}${role}${title} data-href="${href}">${node.text}</a>`
}
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 `<a href="${node.target}"${role} data-href="${node.target}">${text}</a>`
}
}
return this.baseConverter.convert(node, transform)
}
Expand Down

0 comments on commit 32f85f3

Please sign in to comment.