Reputation: 5094
I'm creating an Asciidoctor document with some code blocks. I'm using pygments
as syntax highlighter.
In the output, trailing empty lines in a code block are removed. Normally that's fine, but in some specific case I want to include an empty line after the code in the output.
This should be possible with pygments, since the documentation states:
Currently, all lexers support these options:
stripnl: Strip leading and trailing newlines from the input (default:
True
)
Is it possible to change this option (i.e. to set stripnl=False) for a code block in an Asciidoctor document? If so, how?
A work-around is acceptable if there's no clean way to achieve this. I've considered inserting invisible Unicode characters so the line is not empty, but this seems to cause problems in my IDE (AsciidocFX does not seem to like some Unicode characters) and/or in one of the output formats (HTML and PDF), resulting in garbled output.
example.adoc:
:source-highlighter: pygments
:pygments-style: manni
:pygments-linenums-mode: inline
Some code block here:
```c
void example(void)
{
printf("hello, world\n");
}
```
When compiled using asciidoctor example.adoc -o example.html
, the output is rendered (roughly) like:
Some code block here:
void example(void) { printf("hello, world\n"); }
I'd like to have the code block rendered as
void example(void) { printf("hello, world\n"); } // including this empty line here!
NB: I added the ruby tag, because Asciidoctor and Pygments are written in ruby, and it seems that the configuration of Pygments is done using ruby files as well. I have a strong feeling that the solution requires some Ruby scripts, but I'm not familiar with Ruby myself, so this is far from trivial for me.
In case it's relevant: I'm using Windows 10, Asciidoctor 2.0.17, ruby 3.0.2p107, and pygments.rb 2.3.0.
Upvotes: 1
Views: 325
Reputation: 293
The solution with pass:v[]
did not work for me either using the IntelliJ Asciidoctor plugin. What worked is that I inserted a
\u200F\u200F\u200E \u200E
^
| space here
unicode character set to the end of the last line.
Upvotes: 0
Reputation: 4521
Asciidoctor and Pygments are both stripping the trailing whitespace.
When Pygments is specified as the syntax highlighter, Asciidoctor appears to stop its whitespace removal. That means that you can use a pass-through macro to add a space, provided that you use Asciidoc code blocks:
:source-highlighter: pygments
:pygments-style: manni
:pygments-linenums-mode: inline
Some code block here:
[source, c, subs="macros+"]
----
void example(void)
{
printf("hello, world\n");
}
pass:v[ ]
----
Upvotes: 0