When exporting a document with Preformatted Text sections, 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, the preformatted text is not displayed properly in the exported document. The whitespace should be preserved, and the entire section should be wrapped in `<pre>` tags.
Discussion: https://ask.libreoffice.org/t/preformatted-text-not-being-exported-with-pre-tag-on-export-to-epub/85098
IMHO it could be difficult to decide whether original text is preformatted or not because user is free to create other paragraph styles than Preformatted Text to the job (or have several such styles with differents attributes (indents, colour, …). Would the correct criterion be a fixed-pitched font is used in the paragraph style definition? This may rule out fixed-pitch font applied by a character style or direct formatting over the whole paragraph. But we try to encourage styling, so …
(In reply to ajlittoz from comment #2) You are correct - there may be other styles that need to have the whitespace preserved. In my opinion whitespace should be preserved for the style explicitly named "Preformatted text" and any styles inheriting from it.
Agree that this should be improved if Writer is to be used for documentation and guides related to programming. Similar request for Save as > HTML in bug 36447.
Created attachment 188623 [details] example ODT with tab, space and NBSp indentation In this example document, exporting to PDF preserves the indentations as displayed in Writer. (Although copying the text will not include leading tabs or spaces, and will therefore not be as useful when e.g. pasting into a code editor.) Exporting to EPUB 3.0: - the tab is converted to 15 non-breaking spaces ( ) – which is way too much - indentations consisting of any number of spaces are collapsed to a single non-breaking space - here is a workaround: indentations consisting of non-breaking spaces inserted in Writer with Ctrl + Shift + Space are preserved. Even though this workaround exists, it would be ideal to have normal spaces exported as as many non-breaking spaces instead of collapsing them to a single one (at least as an option). Another related question on ask.lo: https://ask.libreoffice.org/t/epub-output-text-in-frames-all-leading-space-gone-how-to-make-this-work/83185 Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community Build ID: 24d0a62bd75b9a895c419aa165da648ab18f134d CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3 Locale: en-AU (en_AU.UTF-8); UI: en-US Calc: threaded
Created attachment 188624 [details] example ODT exported to EPUB 3.0 with LO 24.2 alpha0+
Also in Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community Build ID: 0e955c4b236bcf9e66e7b49cc3ae285f1a4a9e32 CPU threads: 16; OS: Linux 6.8; UI render: default; VCL: gtk3 Locale: ro-RO (ro_RO.UTF-8); UI: en-US Calc: threaded