Ordered list initial number

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
Silentar
Posts: 8
Joined: Mon Sep 12, 2022 8:22 am

Ordered list initial number

Post by Silentar »

Hello
I am trying to get ordered lists to start from value, defined by attribute
Css, that theoretically should work

Code: Select all

counter-reset: item-count oxy_add(oxy_xpath('../@start'), '-1', number);
If I replace oxy_add part with number it works (so selectors are correct)
oxy_xpath part is correct too - tested by adding :before rule with it as content
Using

Code: Select all

counter-reset: item-count oxy_xpath('../@start');
doesn't work a well
Generated editor html - Image
for

Code: Select all

    <ol id="ol_ew2_345_wwb" start="5">
      <li>asdfsdfg</li>
      <li>dfghfgdhj</li>
    </ol>
Thank you
Bogdan Dumitru
Site Admin
Posts: 142
Joined: Tue Mar 20, 2018 5:28 pm

Re: Ordered list initial number

Post by Bogdan Dumitru »

Hello,

The problem that you encountered is caused by the fact that Oxygen XML Web Author lets the browser evaluate "counter-reset" and "counter-increment" CSS properties but the browser fails to evaluate "oxy_xpath" which is Oxygen-specific.
So you cannot use "oxy_xpath" as a value to the "counter-reset" CSS property in Oxygen XML Web Author.

As a solution, we think that you might be able to define CSS selectors for each value of the "start" attribute, somewhat like this:

Code: Select all

ol[start="1"] {
  counter-reset: item-count 1;
}
ol[start="2"] {
  counter-reset: item-count 2;
}
...
or maybe you can try using "attr" CSS function if possible, maybe like this:

Code: Select all

ol[start] {
  counter-reset: item-count attr(start);
}
Bogdan Dumitru
http://www.oxygenxml.com
Silentar
Posts: 8
Joined: Mon Sep 12, 2022 8:22 am

Re: Ordered list initial number

Post by Silentar »

Thank you for your answer
Unfortunatelly attr doesn't work with counter-reset
But since data-attr-start is generated by Oxygen, it gave me another idea

Code: Select all

document.querySelectorAll('ol[data-attr-start]').forEach(n => n.style.counterReset = 'item-count ' + (n.getAttribute('data-attr-start') - 1));
is called in my plugin and sets OL numbering correctly
Problem left is that change is lost on document change. Currently calling it in setInterval which is not a long-term approach.
Question - how to subscribe to document change (or html redraw) event? Should be obvious but cannot find it in help or forum .
Thank you
Bogdan Dumitru
Site Admin
Posts: 142
Joined: Tue Mar 20, 2018 5:28 pm

Re: Ordered list initial number

Post by Bogdan Dumitru »

Hi,

We strongly suggest not building any customization that relies on the HTML DOM it's not an API of the application, thus you might generate subtle bugs and it might not work in a future version of Oxygen XML Web Author. See the Oxygen SDK for the Java API and the Customizing Web Author Using JavaScript Code for the JS API.

So the only solution for you is to generate a CSS with many matches for most of the "start" attribute values, like this:

Code: Select all

ol[start="1"] {
  counter-reset: item-count 1;
}
ol[start="2"] {
  counter-reset: item-count 2;
}
ol[start="3"] {
  counter-reset: item-count 3;
}
...
Bogdan Dumitru
http://www.oxygenxml.com
Post Reply