Skip to content

Commit

Permalink
Create and keep only one Asciidoctor instance
Browse files Browse the repository at this point in the history
It's much cheaper to reuse an already created instance.

Co-authored-by: Fabian Illner <fabian@illner.dev>
  • Loading branch information
jp7677 and illnr committed Oct 23, 2023
1 parent 8d5e48b commit 15ccc4c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nl.avisi.structurizr.site.generatr.site.model

import org.asciidoctor.Asciidoctor

val asciidoctor: Asciidoctor = Asciidoctor.Factory.create().apply {
javaConverterRegistry().register(AsciiDocTextConverter::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ private fun markdownText(content: String): String {
}

private fun asciidocText(content: String): String {
val asciidoctor = Asciidoctor.Factory.create()
asciidoctor.javaConverterRegistry().register(AsciiDocTextConverter::class.java)

val options = Options.builder().safe(SafeMode.SERVER).backend("text").build()
val text = asciidoctor.convert(content, options)
asciidoctor.shutdown()

return text.lines().joinToString(" ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ private fun Section.markdownTitle(): String {
}

private fun Section.asciidocTitle(): String {
val asciidoctor = Asciidoctor.Factory.create()
val options = Options.builder().safe(SafeMode.SERVER).build()
val document = asciidoctor.load(content, options)
asciidoctor.shutdown()

if (document.title != null && document.title.isNotEmpty())
return document.title

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private fun asciidocToHtml(
asciidoc: String,
svgFactory: (key: String, url: String) -> String?
): String {
val asciidoctor = Asciidoctor.Factory.create()
val options = Options.builder()
.safe(SafeMode.SERVER)
// Docs dir needs to be exposed from structurizr, which is not the case at the moment.
Expand All @@ -69,7 +68,7 @@ private fun asciidocToHtml(
.backend("html5")
.build()
val html = asciidoctor.convert(asciidoc, options)
asciidoctor.shutdown()

return Jsoup.parse(html)
.apply {
body().transformEmbeddedDiagramElements(pageViewModel, svgFactory)
Expand Down

0 comments on commit 15ccc4c

Please sign in to comment.