-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also improve formatting. Co-authored-by: Fabian Illner <[email protected]>
- Loading branch information
Showing
3 changed files
with
26 additions
and
24 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/Asciidoctor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model | ||
|
||
import org.asciidoctor.Asciidoctor | ||
import org.asciidoctor.ast.ContentNode | ||
import org.asciidoctor.ast.Document | ||
import org.asciidoctor.ast.StructuralNode | ||
import org.asciidoctor.converter.ConverterFor | ||
import org.asciidoctor.converter.StringConverter | ||
|
||
val asciidoctor: Asciidoctor = Asciidoctor.Factory.create().apply { | ||
javaConverterRegistry().register(AsciiDocTextConverter::class.java) | ||
} | ||
|
||
@ConverterFor("text") | ||
class AsciiDocTextConverter( | ||
backend: String?, | ||
opts: Map<String?, Any?>? | ||
) : StringConverter(backend, opts) { | ||
// based on https://docs.asciidoctor.org/asciidoctorj/latest/write-converter/ | ||
|
||
override fun convert(node: ContentNode, transform: String?, o: Map<Any?, Any?>?): String? { | ||
val transform1 = transform ?: node.nodeName | ||
return if (node is Document) | ||
node.content.toString() | ||
else if (node is org.asciidoctor.ast.Section) | ||
"${node.title}\n${node.content}" | ||
else if (transform1 == "preamble" || transform1 == "paragraph") | ||
(node as StructuralNode).content as String | ||
else | ||
null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters