Skip to content

Commit 5d8e8aa

Browse files
committed
Merge pull request #22 from philwebb
* pr/22: Support javadoc lookup when package name has a single component Closes gh-22
2 parents f6768bd + 400c612 commit 5d8e8aa

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

lib/javadoc-extension.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ function createLinkMarkup (document, target, description, attributes) {
5454

5555
function getTargetLocation (document, target) {
5656
let name = target.packageReference
57-
let lastDot = name.lastIndexOf('.')
58-
while (lastDot > 0) {
57+
while (name !== '') {
5958
const location = document.getAttribute('javadoc-location-' + name.replaceAll('.', '-'))
6059
if (location) return location
61-
name = name.substring(0, lastDot)
62-
lastDot = name.lastIndexOf('.')
60+
const lastDot = name.lastIndexOf('.')
61+
name = lastDot > 0 ? name.substring(0, lastDot) : ''
6362
}
6463
return document.getAttribute('javadoc-location', 'xref:attachment$api/java')
6564
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/include-code-extension-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ describe('include-code-extension', () => {
307307
include-code::hello[sync-group-id=thisisauniqueid]
308308
`
309309
const actual = run(input, { registerAsciidoctorTabs: true })
310+
console.log(actual.convert())
310311
expect(actual.convert()).to.contain(
311312
'class="openblock tabs is-sync data-sync-group-id=thisisauniqueid is-loading"'
312313
)

test/javadoc-extension-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@ describe('javadoc-extension', () => {
159159
)
160160
})
161161

162+
it('should convert with specified location when has single name package specific javadoc-location attributes', () => {
163+
const input = heredoc`
164+
= Page Title
165+
:javadoc-location: xref:api:java
166+
:javadoc-location-java: xref:api:e1
167+
:javadoc-location-graphql: xref:api:e2
168+
169+
javadoc:java.util.ZipFile[]
170+
javadoc:graphql.collect.ImmutableKit[]
171+
`
172+
const actual = run(input)
173+
expect(actual).to.include(
174+
'<a href="https://docs.example.com/api/e1/java/util/ZipFile.html" class="xref page apiref"><code>ZipFile</code></a>'
175+
)
176+
expect(actual).to.include(
177+
'<a href="https://docs.example.com/api/e2/graphql/collect/ImmutableKit.html" class="xref page apiref"><code>ImmutableKit</code></a>'
178+
)
179+
})
180+
162181
it('should convert with specified location when has xref location in macro', () => {
163182
const input = heredoc`
164183
= Page Title

0 commit comments

Comments
 (0)