Consider the following title block in pandoc-flavored Markdown:
% Higgelty Pigglety Pop!
or
There Must Be More to Life
% Maurice Sendak
% Higgelty Pigglety Pop! \
or \
There Must Be More to Life
% Maurice Sendak
Pandoc Markdown enables the escaped_line_breaks extension by default:
A backslash followed by a newline is also a hard line break. Note: in multiline and grid table cells, this is the only way to create a hard line break, since trailing spaces in the cells are ignored.
A very general, but less simple method is to use raw HTML to indicate line breaks, and to convert them into proper line breaks using a pandoc filter. Below is a Lua filter which translates any <br>
(or <br />
) in the source into a hard line break.
--- Transform a raw HTML element which contains only a `<br>`
-- into a format-indepentent line break.
function RawInline (el)
if el.format:match '^html' and el.text:match '%<br ?/?%>' then
return pandoc.LineBreak()
end
end
Save the file as linebreaks.lua
.
The title could then be written as
% Higgelty Pigglety Pop!<br>or<br>There Must Be More to Life
% Maurice Sendak
The above script must be passed to pandoc via the --lua-filter
option:
$ pandoc -o test.pdf --lua-filter ./linebreaks.lua test.md
The advantage of this method is that it is more universal and also works in other locations that one might want to add line breaks. E.g., a line break in a header can be added using the same syntax: # first line<br>second line
.
When using YAML metadata blocks, the following works, too:
---
title: |
| First line
| Second line
---
Found the idea in this thread.