If you have a recent installation of LaTeX that includes the fvextra package, then there is a simple solution, recently suggested by jannick0.
Modify your YAML header options to include
\usepackage{fvextra}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
and compile with xelatex.
For instance,
---
header-includes:
- \usepackage{fvextra}
- \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
---
~~~~~{.java}
this is a very long long long long long long long long long long long long long line which is broken
~~~~~~
when compiled with
pandoc input.md --pdf-engine=xelatex -o output.pdf
gives
If you had the .numberLines
option, i.e.,
---
header-includes:
- \usepackage{fvextra}
- \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
---
~~~~~{.java .numberLines}
this is a very long long long long long long long long long long long long long line which is broken
~~~~~~
then the same command would produce