Skip to content

Commit

Permalink
resolves #209 open xref from preview (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie authored Oct 2, 2022
1 parent 583c1a9 commit ad1aa32
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 @@ -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()
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 ad1aa32

Please sign in to comment.