Customizing the note element

Post here questions and problems related to editing and publishing DITA content.
jdonges
Posts: 13
Joined: Mon Dec 16, 2019 3:01 pm

Customizing the note element

Post by jdonges »

Hi
I want to customize the output of notes in the PDF transformation with css. There should be no image and no linebreak after the bold "Note: "
Sounds like a simple task fulfilled by:

Code: Select all

*[class ~= "topic/note"]:lang(en):before{
    font-weight: bold;	
    content: "Note: ";
    }
and then likewise for the different subtypes of notes.

But this little code sniplet in my customized css breaks up the whole transformation. It stopps with an error

Code: Select all

 Error on line 183 column 73 of stage1.xml.pp:
     [java]   SXCH0003  org.apache.fop.fo.ValidationException: "fo:table-row" is not a valid child of
     [java]   "fo:table"! (Siehe Position 183:73). Caused by org.apache.fop.fo.ValidationException:
     [java]   file:.../temp/pdf-css-html5/oxygen_dita_temp/stage1.xml.pp:183:73: "fo:table-row" is not a valid child of "fo:table"! (See position 183:73)
In the fo output this not even refers to a note but a hazardstatement.

Any idea whats wrong there?
I'm using Oxygen 25.0 and DITA-OT version 3.7.3

Regards
Jörn
julien_lacour
Posts: 581
Joined: Wed Oct 16, 2019 3:47 pm

Re: Customizing the note element

Post by julien_lacour »

Hi Jörn,

The error message is quite "normal": hazardstatement actually inherits from note (so matching topic/note will match both elements, see DITA Specs) and is displayed as a table, your :before selector tries to add content in this table but doesn't respect the table display.

For what you're trying to achieve, the following rules should be enough:

Code: Select all

*[class ~= "topic/note"] {
  background-image: none !important;
  padding: .75em .5em .75em 0.5em !important;
}

span.note__title {
  display: inline;
}
Regards,
Julien
jdonges
Posts: 13
Joined: Mon Dec 16, 2019 3:01 pm

Re: Customizing the note element

Post by jdonges »

Thanks Julien,

yes this works much better. :D
Although I still have the line break after the note, even when adding !important to the span.note__title rule:
image.png
image.png (7.94 KiB) Viewed 896 times
Here's the rendered HTML

Code: Select all

<span class="note__title">Note:</span>  
            <p class="- topic/p p">The supply voltage is connected to the device casing through protective elements
               exclusively.</p>
I think the problem is that the note element demands a <p> around the text so this will always be a new line.
Regards
Jörn
julien_lacour
Posts: 581
Joined: Wed Oct 16, 2019 3:47 pm

Re: Customizing the note element

Post by julien_lacour »

Hi Jörn,

By default you can write inside a note without adding a paragraph inside it.
From the DITA Specs:

Code: Select all

<note type="tip">Thinking of a seashore, green meadow, or cool
mountain overlook can help you to relax and be more
patient.</note>
Which means your note look like:

Code: Select all

<note>
    <p>The supply voltage is connected to the device casing through protective elements
        exclusively.</p>
</note>
A solution is to unwrap the paragraphs from within the note using Oxygen > Tools > XML Refactoring...
The operation is called "Unwrap element", the XPath will be //note//p and the scope will be Current DITA map hierarchy.

Another solution is to add the following rules to the previous CSS:

Code: Select all

*[class ~= "topic/note"] [class ~= "topic/p"] {
  display: inline;
}
Regards,
Julien
jdonges
Posts: 13
Joined: Mon Dec 16, 2019 3:01 pm

Re: Customizing the note element

Post by jdonges »

Hi Julien,

we have customized DITA and removing the <p> within the note leads to "unexpected character data" error.
However your second solution does what I wanted. Thanks again!

Regards
Jörn
Post Reply