Skip to content

Commit

Permalink
resolves #201 resolve relative PlantUML includes from the diagram dir…
Browse files Browse the repository at this point in the history
…ectory
  • Loading branch information
ggrossetie committed Feb 14, 2021
1 parent a87b2d5 commit 2d2622d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
4 changes: 0 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion src/asciidoctor-kroki.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const processKroki = (processor, parent, attrs, diagramType, diagramText, contex
if (plantUmlInclude) {
diagramText = `!include ${plantUmlInclude}\n${diagramText}`
}
diagramText = require('./preprocess.js').preprocessPlantUML(diagramText, context, doc.getBaseDir())
diagramText = require('./preprocess.js').preprocessPlantUML(diagramText, context, diagramDir)
}
}
const blockId = attrs.id
Expand Down
6 changes: 3 additions & 3 deletions src/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ function removePlantUmlTags (diagramText) {
/**
* @param {string} diagramText
* @param {any} context
* @param {string} baseDir - base directory
* @param {string} diagramDir - diagram base directory
* @returns {string}
*/
module.exports.preprocessPlantUML = function (diagramText, context, baseDir = '.') {
module.exports.preprocessPlantUML = function (diagramText, context, diagramDir = '.') {
const includeOnce = []
const includeStack = []
diagramText = preprocessPlantUmlIncludes(diagramText, baseDir, includeOnce, includeStack, context.vfs)
diagramText = preprocessPlantUmlIncludes(diagramText, diagramDir, includeOnce, includeStack, context.vfs)
return removePlantUmlTags(diagramText)
}

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/docs/diagrams/hello.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!include ./style.puml

Bob->Alice: Hello
1 change: 1 addition & 0 deletions test/fixtures/docs/diagrams/style.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skinparam monochrome true
1 change: 1 addition & 0 deletions test/fixtures/docs/hello.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plantuml::diagrams/hello.puml[]
11 changes: 11 additions & 0 deletions test/preprocess.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const url = require('url')

chai.use(dirtyChai)

const asciidoctorKroki = require('../src/asciidoctor-kroki.js')
const asciidoctor = require('@asciidoctor/core')()

const { preprocessVegaLite } = require('../src/preprocess.js')

describe('Vega-Lite preprocessing', () => {
Expand Down Expand Up @@ -520,4 +523,12 @@ skinparam BackgroundColor black
here -> there`
)
})

it('should resolve PlantUML includes from the diagram directory', () => {
const registry = asciidoctor.Extensions.create()
asciidoctorKroki.register(registry)
const file = path.join(__dirname, 'fixtures', 'docs', 'hello.adoc')
const html = asciidoctor.convertFile(file, { safe: 'safe', extension_registry: registry, to_file: false })
expect(html).to.contain('https://kroki.io/plantuml/svg/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5eJyyk_StXPMyUxOtVLwSM3JyQcAc1EPvA==')
})
})

0 comments on commit 2d2622d

Please sign in to comment.