Preformatted text not being exported with <pre> tag on export to EPUB

When exporting documents as EPUB format, areas with the style “Preformatted Text” are not saved with <pre> tags as expected.

How can I configure LibreOffice to properly use the <pre> tag in EPUB exported documents for the style “Preformatted Text”?

Currently using LibreOffice 7.4 on Ubuntu.

How does it export presently?

Each individual line of the Preformatted Text section is wrapped with <p class="para3"><span class="span4">, and all leading whitespace is removed.

Because the whitespace is removed, I cannot even write e.g. a Python script to unpack the epub and add maybe a CSS rule.

This is consistent with generic Writer behaviour. There is no link between ODF XML encoding and HTML. Styles are translated as <p class=…> for paragraph and <span class=…> for character styles. The association with a specific font (proportional or fixed-pitch) is done with CSS. After all, <pre> interpretation by browser relies on an implicit default CSS sheet.

I see, thank you.

For my use case, writing code examples, the <pre> tag is necessary to preserve indentation. What workarounds are possible? I’ve tried using Manual Row Breaks (that resolves an issue that I didn’t yet mention: borders around the styled area are duplicated on each line, so there is a border between each line) but that does not resolve the removal of indentation.

I am not familiar with EPUB. If it is similar to HTML and you can provide a CSS stylesheet, define the properties as they are defined for <pre> in HTML.
Regarding indentation, the CSS configuration is sufficient IF spaces are exported and not merged into a single one. If this is not the case, I don’t know how to force it. In principle Preformatted Text should preserve multiple spaces but I have no experience with the EPUB export filter (it may well damge what Writer handles to it).

Thank you. I have filed a bug on the EPUB export filter not preserving whitespace in Prefomatted Text:

https://bugs.documentfoundation.org/show_bug.cgi?id=152469