Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preprocess of subfolder includes for antora #455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ function resolveIncludeFile (includeFile, resource, includePaths, vfs) {
const exists = typeof vfs !== 'undefined' && typeof vfs.exists === 'function' ? vfs.exists : require('./node-fs.js').exists
if (resource.module) {
// antora resource id
return includeFile
const dirPath = path.dirname(resource.relative)
return path.join(dirPath, includeFile)
}
let filePath = includeFile
for (const includePath of [resource.dir, ...includePaths]) {
Expand Down
10 changes: 10 additions & 0 deletions test/antora/docs/modules/ROOT/pages/source-location.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ plantuml::partial$ab_inc.puml[target=ab-inc-partial-1,format=svg]

NOTE: `ab_inc.puml` is using the PlantUML `!include` directive to include another file.

== Include a partial from subfolder using plantuml macro

....
plantuml::partial$sub/ab_sub_inc.puml[target=ab-inc-sub-partial-1,format=svg]
....

plantuml::partial$sub/ab_sub_inc.puml[target=ab-inc-sub-partial-1,format=svg]

NOTE: `sub/ab_sub_inc.puml` is using the PlantUML `!include` directive to include another file.

== Include an example (.puml extension)

....
Expand Down
3 changes: 3 additions & 0 deletions test/antora/docs/modules/ROOT/partials/sub/ab_sub_inc.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@startuml
!include sub/ab_sub_sub_inc.puml
@enduml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@startuml
!include sub/ab_sub_sub_sub.puml
@enduml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alice -> bob
bob -> alice
11 changes: 10 additions & 1 deletion test/antora/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Antora integration (local)', function () {
it('should generate a site with diagrams', () => {
const $ = cheerio.load(fs.readFileSync(`${__dirname}/public/antora-kroki/source-location.html`))
const imageElements = $('img')
expect(imageElements.length).to.equal(7)
expect(imageElements.length).to.equal(8)
imageElements.each((i, imageElement) => {
const src = $(imageElement).attr('src')
expect(src).to.startWith('_images/ab-')
Expand All @@ -32,6 +32,15 @@ describe('Antora integration (local)', function () {
expect(diagramContents).includes('alice')
expect(diagramContents).includes('bob')
})
it('should resolve included diagrams from subfolders when using plantuml::partial$subfolder/xxx.puml[] macro', async () => {
const $ = cheerio.load(fs.readFileSync(`${__dirname}/public/antora-kroki/source-location.html`))
const imageElement = $('img[alt*=ab-inc-sub-partial-1]')
expect(imageElement.length).to.equal(1)
const src = imageElement.attr('src')
const diagramContents = fs.readFileSync(`${__dirname}/public/antora-kroki/${src}`).toString()
expect(diagramContents).includes('alice')
expect(diagramContents).includes('bob')
})
})

describe('Antora integration (remote)', function () {
Expand Down