Bug 152469 - EPUB export: Preformatted text not being exported with leading whitespace
Summary: EPUB export: Preformatted text not being exported with leading whitespace
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.4.3.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL: https://ask.libreoffice.org/t/preform...
Whiteboard:
Keywords:
Depends on:
Blocks: EPUB-Export
  Show dependency treegraph
 
Reported: 2022-12-11 16:47 UTC by Dotan Cohen
Modified: 2024-09-29 15:06 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
example ODT with tab, space and NBSp indentation (13.40 KB, application/vnd.oasis.opendocument.text)
2023-07-28 22:38 UTC, Stéphane Guillou (stragu)
Details
example ODT exported to EPUB 3.0 with LO 24.2 alpha0+ (2.46 KB, application/epub+zip)
2023-07-28 22:39 UTC, Stéphane Guillou (stragu)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dotan Cohen 2022-12-11 16:47:24 UTC
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.
Comment 2 ajlittoz 2022-12-11 17:17:19 UTC
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 …
Comment 3 Dotan Cohen 2022-12-19 15:15:57 UTC
(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.
Comment 4 Stéphane Guillou (stragu) 2023-07-28 22:14:02 UTC
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.
Comment 5 Stéphane Guillou (stragu) 2023-07-28 22:38:25 UTC
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 (&nbsp;) – 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
Comment 6 Stéphane Guillou (stragu) 2023-07-28 22:39:13 UTC
Created attachment 188624 [details]
example ODT exported to EPUB 3.0 with LO 24.2 alpha0+
Comment 7 BogdanB 2024-09-29 15:06:57 UTC
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