ietf-tools / xml2rfc

Generate RFCs and IETF drafts from document source in XML according to the IETF xml2rfc v2 and v3 vocabularies
https://ietf-tools.github.io/xml2rfc/
BSD 3-Clause "New" or "Revised" License
68 stars 38 forks source link

Styling of dl with indent="x" #856

Open martinthomson opened 2 years ago

martinthomson commented 2 years ago

The current version of xml2rfc generates definition lists with an per-element override on every <dd> item that is set to 0.5em times the value of the indent attribute on the <dl>. Aside from being repetitious, this presents a challenge for styling of these elements.

It is possible to produce a style rule that correctly styles definition lists without this. That rule looks like:

dl[indent] > dd {
  margin-left: attr(indent ch);
}

In markup, this would only involve propagating the XML indent attribute onto the HTML.

The CSS style rule is not well supported in browsers, so it is probably necessary to manually expand the rule like this for now:

dl[indent=1]>dd { margin-left: 1ch; }
dl[indent=2]>dd { margin-left: 2ch; }
/* repeat as many times as desired; some approximation may be acceptable for larger numbers */

Even with a lot of these, this is more efficient than the current approach once you have a few definition lists. Importantly, it doesn't override styling. Restyling lists with per-element style attributes is quite difficult.

Note: I've used ch units here, which aren't quite an en-width, but there is no equivalent in CSS. Either way, an en-width is not half of an em-width, so using ch is a better fit.

martinthomson commented 2 years ago

FWIW, I tried a few things that don't work:

dl { --indent: 3ch; }
dl[indent] { --indent: calc(attr(indent) * 1ch); }
dl > dd { margin-left: var(--indent); }

That does suggest a way to compress the above though:

dl[indent="3"] { --dli: 3ch; }
/* and so on */
dl > dd { margin-left: var(--dli); }