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

Asciidoc support #307

Closed
wants to merge 2 commits into from
Closed

Asciidoc support #307

wants to merge 2 commits into from

Conversation

illnr
Copy link
Contributor

@illnr illnr commented Sep 7, 2023

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

Copy link
Contributor

@jp7677 jp7677 left a 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)
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

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/
Copy link
Contributor

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"))
Copy link
Contributor

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
Copy link
Contributor

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.

@jp7677
Copy link
Contributor

jp7677 commented Oct 22, 2023

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 :(
Not yet really sure how that happened since git branch -avv showd my origins, but I must have screwed up somewhere. Feel free of course to update your branch again.

@jp7677 jp7677 mentioned this pull request Oct 22, 2023
@jp7677
Copy link
Contributor

jp7677 commented Oct 22, 2023

@illnr I took the liberty to continue your work. So this PR is now superseded by #336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

asciidoc support
3 participants