docToolchain icon indicating copy to clipboard operation
docToolchain copied to clipboard

Confluence page does not render code callouts properly

Open LuisMuniz opened this issue 5 years ago • 11 comments

One of my favorite features of asciidoctor is to be able to add callouts to code blocks, like this:

[source,yaml]
.Add cli to your docker-compose.yml
----
  cli:
    image: cli:v2.0.5
    entrypoint: "tail" <1>
    command: ["-f","/dev/null"] <1>
----
<1> This will override the default entrypoint `cli.sh` and just hang with a `tail -f /dev/null` to prevent docker from exiting. See link:../infrastructure/cli-docker.html[Article on cli] for details.

However Confluence does not seem to support this in their own code blocks.

When asciidoc2confluence rewrites the generated HTML to translate them to Confluence code blocks, the resulting callouts in the code block show as inlined HTML in the code, something like this:

cli:
  image: cli:v2.0.5
  entrypoint: "tail" <i class="conum" data-value="1"></i><b>(1)</b>
  command: ["-f","/dev/null"] <i class="conum" data-value="1"></i><b>(1)</b>

Is it possible to just disable rewriting the code block, so that it is not recognized by confluence as a code block, and thus not to suffer from their limitations?

To Reproduce

  1. Add a code block with callouts to your asciidoctor file
  2. publishToConluence
  3. See resulting Confluence page

Expected behavior That the uploaded confluence page shows callouts like a normal asciidoctor rendered HTML page.

LuisMuniz avatar May 22 '19 04:05 LuisMuniz

good idea, we can give it a try. But I guess that the code will then not get syntax highlighted...

you can give it a try by commenting out this line https://github.com/docToolchain/docToolchain/blob/master/scripts/asciidoc2confluence.groovy#L336

It should do the trick that the code block does not get rewritten...

If you do so, could you post screenshots of both rendereings?

rdmueller avatar May 22 '19 21:05 rdmueller

Sure I'll post the screenshots

LuisMuniz avatar May 23 '19 06:05 LuisMuniz

This is the rendering produced by Asciidoctor:

asciidoctor-rendering

This is the rendering in Confluence with the current script: default-code-conversion

This is the rendering in Confluence when shorting out the rewriteCodeblocks method: no-code-conversion

The no-conversion block looks ok, but we are of course sacrificing the code syntax highlighting.

I don't know enough html/css - fu to find a better solution than to just remove code conversion, b ut maybe there is a way to add some inline CSS styles to the <b> element to make it look better, or inline a confluence macro? I' m really out of my depth here.

LuisMuniz avatar Jul 17 '19 14:07 LuisMuniz

Is there an elegant way that you can think of, to allow your script to exclude generating a confluence code block, maybe by adding some special comment? I'm not sure that Asciidoctor comments are actually generating anything in the final html.

Maybe we could add an inocuous asciidoc code block option that will have a visible and parseable html result? Then the rewriteCodeblocks script could change its behaviour.

I guess I'm just asking if you've already had to do stuff like this in the project, and if yes, what's the recommended way.

emfanitek avatar Aug 19 '19 10:08 emfanitek

I opened a PR. This works for our Confluence Version (6.13.3). I hope, this works on others, too.

It just does a line comment ("//") before the callout.

Maybe there is a more general solution that uses the correct comment chars for the programing language.

bohni avatar Jan 22 '20 13:01 bohni

PR merged. Would be cool to get feedback.

rdmueller avatar Jan 22 '20 19:01 rdmueller

Oh, this is cool. I'll give feedback as soon as I find some O2 for this.

LuisMuniz avatar Jan 23 '20 11:01 LuisMuniz

I just patched my local installation with the changes from the PR. Looks good to me.

hbrands avatar Feb 07 '20 13:02 hbrands

I just patched my local installation with the changes from the PR. Looks good to me.

@hbrands I just realized, that on our confluence this only renders correct, if we don't use subpages. Can you confirm or disprove this?

bohni avatar Feb 07 '20 14:02 bohni

@bohni I tested with configuration createSubpages = false

hbrands avatar Feb 07 '20 14:02 hbrands

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a small comment to keep it open. Thank you for your contributions.

stale[bot] avatar Aug 13 '20 14:08 stale[bot]