white-space:normal CSS selector doesn’t work with <lines>, apparently

Post here questions and problems related to editing and publishing DITA content.
Vinny
Posts: 16
Joined: Wed Jan 12, 2022 1:07 pm

white-space:normal CSS selector doesn’t work with <lines>, apparently

Post by Vinny »

Folks,

As far as I understand the DITA norm, the <lines> tag preserves linefeeds but discards multiple spaces.
However, using the DITA/CSS transform, I find that both linefeeds and spaces are preserved, much like if white-space:pre was implied (or <codeblock> used).
I tried to override this behaviour using a dedicated CSS section:

Code: Select all

.lines {
    white-space: normal;
}
But that doesn’t work. The <line> tag is transformed into:
<lines class="- topic/lines " xml:space="preserve">

and the xml:space property seems to take precedence over the CSS.
Any idea how I can fix this? Thanks a bunch in advance.
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: white-space:normal CSS selector doesn’t work with <lines>, apparently

Post by Radu »

Hi,
You are publishing DITA content to PDF using CSS or to WebHelp output?
The DITA specification DTDs defines the xml:space=preserve as a default attribute for the DITA <lines> element. And the DTDs are provided by the OASIS technical committee which is in charge of developing the standard, this is not something we control.
So this is why that attribute appears when you publish the content (probably you were looking in the temporary files folder).
And the xml:space attribute present in the XML is stronger than CSS rules.
Not sure what to advice in this case, I think you can either:
1) Create a DITA DTD specialization which no longer defines this attribute on <lines> which is quite hard to do and impractical to maintain:
https://www.oxygenxml.com/doc/versions/ ... ation.html
2) Add some sort of publishing XSLT customization which matches on the <lines> element and removes this xml:space attribute.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Vinny
Posts: 16
Joined: Wed Jan 12, 2022 1:07 pm

Re: white-space:normal CSS selector doesn’t work with <lines>, apparently

Post by Vinny »

Hi Radu,
thanks for your answer.
The norm seems contradictory to me, but, as you emphasised, this is not your fault :)
Isn't there a way to insert the execution of a small script (in Python, or just plain shell) just before FO begins to parse the expanded XML source?
Multumesc,
Vincent
julien_lacour
Posts: 495
Joined: Wed Oct 16, 2019 3:47 pm

Re: white-space:normal CSS selector doesn’t work with <lines>, apparently

Post by julien_lacour »

Hello Vincent,

This issue has already been addressed to DITA-OT: https://github.com/dita-ot/dita-ot/issues/4108
To avoid this situation, you can for example create a Schematron file with the following content:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
  <pattern id="lines-spaces">
    <rule context="lines">
      <report test="contains(text(), '&#x20;&#x20;')" role="warn" sqf:fix="removeExtraSpaces">Lines contains multiple spaces.</report>
      <sqf:fix id="removeExtraSpaces">
        <sqf:description>
          <sqf:title>Remove extra spaces.</sqf:title>
        </sqf:description>
        <sqf:stringReplace match="text()" regex="&#x20;&#x20;" select="'&#x20;'"/>
      </sqf:fix>
    </rule>
  </pattern>
</schema>
Then, add this file into a custom validation scenario or the DITA framework default validation.
A warning will appear for each <lines> with multiple spaces and the quickfix will correct the element directly.

Regards,
Julien
Vinny
Posts: 16
Joined: Wed Jan 12, 2022 1:07 pm

Re: white-space:normal CSS selector doesn’t work with <lines>, apparently

Post by Vinny »

Awesome! I’m going to try that. Thanks so much!
Merci beaucoup ! Bonne fin de journée !
V.
Post Reply