Skip to content

Commit

Permalink
Support javadoc lookup when package name has a single component
Browse files Browse the repository at this point in the history
Fix `lib/javadoc-extension.js` so that package lookups also work when
the package has a single component. Prior to this commit, a lookup
such as `javadoc-location-java: '{url-jdk-javadoc}'` would not work.

Fixes spring-iogh-22
  • Loading branch information
philwebb committed Nov 12, 2024
1 parent f6768bd commit b808647
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/javadoc-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ function createLinkMarkup (document, target, description, attributes) {

function getTargetLocation (document, target) {
let name = target.packageReference
let lastDot = name.lastIndexOf('.')
while (lastDot > 0) {
while (name !== '') {
const location = document.getAttribute('javadoc-location-' + name.replaceAll('.', '-'))
if (location) return location
name = name.substring(0, lastDot)
lastDot = name.lastIndexOf('.')
const lastDot = name.lastIndexOf('.')
name = (lastDot > 0) ? name.substring(0, lastDot) : ''
}
return document.getAttribute('javadoc-location', 'xref:attachment$api/java')
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/include-code-extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ describe('include-code-extension', () => {
include-code::hello[sync-group-id=thisisauniqueid]
`
const actual = run(input, { registerAsciidoctorTabs: true })
console.log(actual.convert())
expect(actual.convert()).to.contain(
'class="openblock tabs is-sync data-sync-group-id=thisisauniqueid is-loading"'
)
Expand Down
19 changes: 19 additions & 0 deletions test/javadoc-extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ describe('javadoc-extension', () => {
)
})

it('should convert with specified location when has single name package specific javadoc-location attributes', () => {
const input = heredoc`
= Page Title
:javadoc-location: xref:api:java
:javadoc-location-java: xref:api:e1
:javadoc-location-graphql: xref:api:e2
javadoc:java.util.ZipFile[]
javadoc:graphql.collect.ImmutableKit[]
`
const actual = run(input)
expect(actual).to.include(
'<a href="https://docs.example.com/api/e1/java/util/ZipFile.html" class="xref page apiref"><code>ZipFile</code></a>'
)
expect(actual).to.include(
'<a href="https://docs.example.com/api/e2/graphql/collect/ImmutableKit.html" class="xref page apiref"><code>ImmutableKit</code></a>'
)
})

it('should convert with specified location when has xref location in macro', () => {
const input = heredoc`
= Page Title
Expand Down

0 comments on commit b808647

Please sign in to comment.