Page 1 of 1

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

Posted: Tue May 23, 2023 11:22 am
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.

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

Posted: Tue May 23, 2023 1:53 pm
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

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

Posted: Wed May 24, 2023 11:25 am
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

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

Posted: Thu May 25, 2023 2:06 pm
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

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

Posted: Thu May 25, 2023 3:58 pm
by Vinny
Awesome! I’m going to try that. Thanks so much!
Merci beaucoup ! Bonne fin de journée !
V.