-
Notifications
You must be signed in to change notification settings - Fork 37
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
Asciidoc support #307
Asciidoc support #307
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very sorry for the late response. This PR looks very good, thanks a lot for your contribution.
Please see my comments/suggestions.
fun asciidocToHtml(pageViewModel: PageViewModel, asciidoc: String, svgFactory: (key: String, url: String) -> String?): String { | ||
val asciidoctor = Asciidoctor.Factory.create() | ||
val options = Options.builder() | ||
.safe(SafeMode.SERVER) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please align the indentation here (and in other places) with the rest of the project?
private val parser = Parser.builder().build() | ||
private const val MAX_TITLE_LENGTH = 50 | ||
|
||
fun Section.contentTitle(): String { | ||
if (format != Format.Markdown) | ||
if (format != Format.Markdown && format != Format.AsciiDoc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using when
would handle this more elegantly.
val document = parser.parse(content) | ||
|
||
if (!document.hasChildren()) | ||
fun asciidocTitle(): String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have those methods on the top level but private in this file.
return "unknown document" | ||
} | ||
|
||
if (format == Format.AsciiDoc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be combined with above mentioned when
.
build.gradle.kts
Outdated
@@ -27,6 +27,7 @@ dependencies { | |||
implementation("net.sourceforge.plantuml:plantuml:1.2023.10") | |||
|
|||
implementation("com.vladsch.flexmark:flexmark-all:0.64.8") | |||
implementation("org.asciidoctor:asciidoctorj:2.5.10") // TODO: compile()? see https://docs.asciidoctor.org/asciidoctorj/latest/installation/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation
is fine, that todo can imho be removed.
// Needed for partial include `include::partial.adoc[]`, which structurizr also does not support. | ||
// see https://docs.asciidoctor.org/asciidoc/latest/directives/include/ | ||
// another option could be https://docs.asciidoctor.org/asciidoctorj/latest/locating-files/#globdirectorywalker-class | ||
// .baseDir(File("./docs/example/workspace-docs")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please expand that comment with the consequences of not having a baseDir
?
fun toHtml(format: Format, pageViewModel: PageViewModel, content: String, svgFactory: (key: String, url: String) -> String?): String = when(format) { | ||
Format.AsciiDoc -> asciidocToHtml(pageViewModel, content, svgFactory) | ||
Format.Markdown -> markdownToHtml(pageViewModel, content, svgFactory) | ||
else -> markdownToHtml(pageViewModel, content, svgFactory) // ensures past behaviour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reach the else branch here in real life? Generating "unsupported document" like above would be an alternative.
Ruby runtime maybe needs improvement: https://docs.asciidoctor.org/asciidoctorj/latest/ruby-runtime/
671a055
to
0b035bb
Compare
Hi @illnr I'm sorry, seems that I pushed accidentally to your branch instead of my own ( https://github.com/jp7677/structurizr-site-generatr/tree/asciidoc-support ) while playing with your code :( |
Adds support for Asciidoc for documentation files, but not for ADRs since it is also not supported by Structurizr.
Adding dependency AsciidoctorJ for Asciidoc conversion.
Since the outputted html from Asciidoctor (using the default template) is different to the Markdown converted html, I used jsoup to add bulma (css) classes to get the (somehow) same look.
I also adapted the admonition.css for default Asciidoctor converted html files and to supported single nested admonitions with correct background colours.
This was my first time programming anything with Kotlin, so any feedback appreciated. Last time I programmed Java was more than 10 years ago.
Closes #282