Using CSS to format HTML and Enhanced Tabular Fields

The enable CSS support, edit the field options and press the   button next to the HTML option:

This opens a dialog with a set of options, one of which is CSS and provides the ability to edit the stylesheet.

This enables the use of CSS style markup. The attributes  are not HTML attributes, but specific attributes provided by EasyCatalog. Take this example:

The style node specifies a character-color for the text in the paragraph. If the HTML contained no formatting:

Then we can define stylesheets to apply attributes using a basic CSS parser. For example:

Working with tables

Taking this simple table:

To color the header and an alternating rows, the following stylesheets can be defined:

if the HTML contained a class attribute, eg:

Then a stylesheet can pick this out:

The width of columns can be specified by using the cell-width property on the td or th tag:

Using stylesheets with Tabular Fields

Stylsheets can be applied to tabular fields. For example, using the HTML above we can create an Enhanced tabular field with the following stylesheet:

Stylesheets are applied uniformly to all enhanced tabular fields, regardless of their original source type. Each tabular field is treated as an implied HTML table for CSS processing purposes, with its structure represented through standard elements such as <table>, <tr>, <th>, and <td> nodes.

This design allows CSS rules to be applied consistently across all tabular data, enabling flexible styling and formatting. Stylesheets can also be added during post-processing, after the tabular field has been generated, to further refine its appearance.

For example, a stylesheet can be defined to apply a background color to the cells corresponding to a specific city:

The Additional Processing Lua code can then specify the cells class:

Without using a stylesheet, css style information can be set explicitly:

Another feature is the define CSS styles based on the content of the tabular fields. The contents of row cells are added as attributes to the CSS processor (The names of fields called id, class or style are prefixed with field-). So entire row can be styled of the contents of the City field by. For example:

Targeting tables by their id

The following HTML contains 2 tables with ids:

The following stylesheets targets specific tables be their ID:

This produces the following output:

Sharing CSS between fields

If the CSS just contains the name of a file in the data sources scripts folder, this is loaded and used.

Other Considerations

Stylesheet information is stored at a cell level, so when a field is populated  which has cell based attributes, these are applied irrespective of where a field is in a table.

Supported Selectors

The CSS parser is basic and evaluates whether a single HTML-like node matches a given CSS selector. The following selector types are supported:

1. Tag Selector

  • Matches elements by their tag name.
  • Examples:
    • div — matches all <div> elements
    • * — wildcard, matches any element

2. ID Selector

  • Matches elements by their id attribute.
  • Syntax: #idName
  • Example: #main — matches element with id="main"

3. Class Selector

  • Matches elements by their class attribute.
  • Syntax: .className
  • Multiple classes can be chained: .foo.bar
  • Matches elements containing all specified classes.

4. Attribute Selectors

  • Match elements based on attribute values.
  • Supported operators:
    • [attr=value] — exact match
    • [attr~=value] — whitespace-separated list contains value
    • [attr|=value] — equals value or starts with value-
    • [attr^=value] — starts with value
    • [attr$=value] — ends with value
    • [attr*=value] — contains value

5. Structural Pseudo-Classes

Target elements based on their position or type among siblings:

Pseudo-ClassDescription
:first-childMatches the first child of its parent
:last-childMatches the last child of its parent
:nth-child(n)Matches the nth child (1-based) of its parent
:nth-last-child(n)Matches the nth child from the end
:first-of-typeMatches the first element of its type among siblings
:last-of-typeMatches the last element of its type among siblings
:nth-of-type(n)Matches the nth element of its type among siblings
:nth-last-of-type(n)Matches the nth element of its type from the end
:only-childMatches the only child of its parent
:only-of-typeMatches the only element of its type among siblings
:emptyMatches elements with no children (no elements, text, or comments)

Note: nth-child and similar formulas support CSS-style numeric formulas (e.g., 2, 3n+1, odd, even)

Supported Attributes

The following list is complete at the time of writing, an up-to-date list can be generated at any time by pressing the info icon when editing a CSS stylesheet.

ModifiesNameExpects
tablescell-clip-contentsboolean
tablescell-fill-colorstring
tablescell-fill-overprintboolean
tablescell-fill-tintpercentage
tablescell-first-baseline-minmeasure
tablescell-first-baseline-offsetstring
tablescell-heightmeasure
tablescell-inset-bottommeasure
tablescell-inset-leftmeasure
tablescell-inset-rightmeasure
tablescell-inset-topmeasure
tablescell-stroke-color-bottomstring
tablescell-stroke-color-leftstring
tablescell-stroke-color-rightstring
tablescell-stroke-color-topstring
tablescell-stroke-overprint-bottompercentage
tablescell-stroke-overprint-leftpercentage
tablescell-stroke-overprint-rightpercentage
tablescell-stroke-overprint-toppercentage
tablescell-stroke-tint-bottompercentage
tablescell-stroke-tint-leftpercentage
tablescell-stroke-tint-rightpercentage
tablescell-stroke-tint-toppercentage
tablescell-stroke-weight-bottommeasure
tablescell-stroke-weight-leftmeasure
tablescell-stroke-weight-rightmeasure
tablescell-stroke-weight-topmeasure
tablescell-stylestring
tablescell-text-rotationdegrees
tablescell-vertical-justificationbottom, center, justify, top
tablescell-vertical-justification-paragraph-spacing-limitmeasure
tablescell-widthmeasure
tablesrow-keep-start-rowanywhere, next-column, next-even-page, next-frame, next-odd-page, next-page
tablesrow-keep-with-nextboolean
tablesrow-maximum-heightmeasure
tablesrow-minimum-heightmeasure
tablestable-border-stroke-colorstring
tablestable-border-stroke-tintpercentage
tablestable-border-stroke-typedash3x2, dash4x4, dashed, dotted, japanese-dots, left-slant-hash, right-slant-hash, solid, straight-hash, thick-thick, thick-thin, thick-thin-thick, thin-thick, thin-thick-thin, thin-thin, triple, wavy, white-diamond
tablestable-border-stroke-weightmeasure
tablestable-space-aftermeasure
tablestable-space-beforemeasure
tablestable-stylestring
tablestable-widthmeasure
textcharacter-caselowercase, none, small-everything, small-lowercase, uppercase
textcharacter-colorstring
textcharacter-font-familystring
textcharacter-font-stylestring
textcharacter-leadingmeasure
textcharacter-positionnormal, subscript, superscript
textcharacter-sizestring
textcharacter-strikethroughboolean
textcharacter-strikethrough-colorstring
textcharacter-strikethrough-gap-colorstring
textcharacter-strikethrough-gap-tintpercentage
textcharacter-strikethrough-offsetmeasure
textcharacter-strikethrough-overprint-gapboolean
textcharacter-strikethrough-overprint-strokeboolean
textcharacter-strikethrough-tintpercentage
textcharacter-strikethrough-typedash3x2, dash4x4, dashed, dotted, japanese-dots, left-slant-hash, right-slant-hash, solid, straight-hash, thick-thick, thick-thin, thick-thin-thick, thin-thick, thin-thick-thin, thin-thin, triple, wavy, white-diamond
textcharacter-strikethrough-weightmeasure
textcharacter-stylestring
textcharacter-underlineboolean
textcharacter-underline-colorstring
textcharacter-underline-gap-colorstring
textcharacter-underline-gap-tintpercentage
textcharacter-underline-offsetmeasure
textcharacter-underline-overprint-gapboolean
textcharacter-underline-overprint-strokeboolean
textcharacter-underline-tintpercentage
textcharacter-underline-typedash3x2, dash4x4, dashed, dotted, japanese-dots, left-slant-hash, right-slant-hash, solid, straight-hash, thick-thick, thick-thin, thick-thin-thick, thin-thick, thin-thick-thin, thin-thin, triple, wavy, white-diamond
textcharacter-underline-weightmeasure
textparagraph-alignaway-from-spine, center, justify, justify-center, justify-full, justify-left, justify-right, left, right, to-spine
textparagraph-borderboolean
textparagraph-border-bottom-edgebaseline, descent
textparagraph-border-capbut-cap, projecting-cap, round-cap
textparagraph-border-corner-radius-bottom-leftmeasure
textparagraph-border-corner-radius-bottom-rightmeasure
textparagraph-border-corner-radius-top-leftmeasure
textparagraph-border-corner-radius-top-rightmeasure
textparagraph-border-corner-type-bottom-leftbevel, fancy, inset, inverse-rounded, rounded
textparagraph-border-corner-type-bottom-rightbevel, fancy, inset, inverse-rounded, rounded
textparagraph-border-corner-type-top-leftbevel, fancy, inset, inverse-rounded, rounded
textparagraph-border-corner-type-top-rightbevel, fancy, inset, inverse-rounded, rounded
textparagraph-border-display-if-splitsboolean
textparagraph-border-gap-tintpercentage
textparagraph-border-gap-tint-overprintboolean
textparagraph-border-joinbevel-join, miter-join, round-join
textparagraph-border-merge-consecutiveboolean
textparagraph-border-offset-bottommeasure
textparagraph-border-offset-leftmeasure
textparagraph-border-offset-rightmeasure
textparagraph-border-offset-topmeasure
textparagraph-border-stroke-bottommeasure
textparagraph-border-stroke-colorstring
textparagraph-border-stroke-gap-colorstring
textparagraph-border-stroke-leftmeasure
textparagraph-border-stroke-rightmeasure
textparagraph-border-stroke-topmeasure
textparagraph-border-stroke-typedash3x2, dash4x4, dashed, dotted, japanese-dots, left-slant-hash, right-slant-hash, solid, straight-hash, thick-thick, thick-thin, thick-thin-thick, thin-thick, thin-thick-thin, thin-thin, triple, wavy, white-diamond
textparagraph-border-top-edgeascent, baseline, leading
textparagraph-border-widthcolumn, text
textparagraph-bullets-alignmentstring
textparagraph-bullets-numbering-typebullet, none, number
textparagraph-bullets-text-afterstring
textparagraph-hyphenation-hyphenate-across-columnboolean
textparagraph-hyphenation-hyphenate-capitalised-wordsboolean
textparagraph-hyphenation-hyphenate-last-wordboolean
textparagraph-hyphenation-methodalgorithm, dictionary, manual, off
textparagraph-hyphenation-settings-after-first-lettersinteger
textparagraph-hyphenation-settings-before-last-lettersinteger
textparagraph-hyphenation-settings-better-spacing-fewer-hyphensinteger
textparagraph-hyphenation-settings-hyphen-limit-hyphensinteger
textparagraph-hyphenation-settings-hyphenateboolean
textparagraph-hyphenation-settings-hyphenate-zonemeasure
textparagraph-hyphenation-settings-words-with-at-least-lettersinteger
textparagraph-indent-first-line-leftmeasure
textparagraph-indent-last-line-rightmeasure
textparagraph-indent-leftmeasure
textparagraph-indent-rightmeasure
textparagraph-keep-options-all-lines-in-paragraphboolean
textparagraph-keep-options-at-start-end-of-paragraphboolean
textparagraph-keep-options-end-linesinteger
textparagraph-keep-options-keep-lines-togetherboolean
textparagraph-keep-options-keep-with-next-linesinteger
textparagraph-keep-options-keep-with-previousboolean
textparagraph-keep-options-start-linesinteger
textparagraph-keep-options-start-paragraphstring
textparagraph-rule-aboveboolean
textparagraph-rule-above-colorstring
textparagraph-rule-above-gap-colorstring
textparagraph-rule-above-gap-overprintboolean
textparagraph-rule-above-gap-tintpercentage
textparagraph-rule-above-keep-in-frameboolean
textparagraph-rule-above-left-indentmeasure
textparagraph-rule-above-offsetmeasure
textparagraph-rule-above-overprint-strokeboolean
textparagraph-rule-above-right-indentmeasure
textparagraph-rule-above-tintpercentage
textparagraph-rule-above-typestring
textparagraph-rule-above-weightmeasure
textparagraph-rule-above-widthstring
textparagraph-rule-belowboolean
textparagraph-rule-below-colorstring
textparagraph-rule-below-gap-colorstring
textparagraph-rule-below-gap-overprintboolean
textparagraph-rule-below-gap-tintpercentage
textparagraph-rule-below-keep-in-frameboolean
textparagraph-rule-below-left-indentmeasure
textparagraph-rule-below-offsetmeasure
textparagraph-rule-below-overprint-strokeboolean
textparagraph-rule-below-right-indentmeasure
textparagraph-rule-below-tintpercentage
textparagraph-rule-below-typestring
textparagraph-rule-below-weightmeasure
textparagraph-rule-below-widthstring
textparagraph-shadingboolean
textparagraph-shading-bottom-edgebaseline, descent
textparagraph-shading-clip-to-frameboolean
textparagraph-shading-colorstring
textparagraph-shading-corner-radius-bottom-leftmeasure
textparagraph-shading-corner-radius-bottom-rightmeasure
textparagraph-shading-corner-radius-top-leftmeasure
textparagraph-shading-corner-radius-top-rightmeasure
textparagraph-shading-corner-type-bottom-leftbevel, fancy, inset, inverse-rounded, rounded
textparagraph-shading-corner-type-bottom-rightbevel, fancy, inset, inverse-rounded, rounded
textparagraph-shading-corner-type-top-leftbevel, fancy, inset, inverse-rounded, rounded
textparagraph-shading-corner-type-top-rightbevel, fancy, inset, inverse-rounded, rounded
textparagraph-shading-do-not-printboolean
textparagraph-shading-offset-bottommeasure
textparagraph-shading-offset-leftmeasure
textparagraph-shading-offset-rightmeasure
textparagraph-shading-offset-topmeasure
textparagraph-shading-overprintboolean
textparagraph-shading-tintpercentage
textparagraph-shading-top-edgeascent, baseline, leading
textparagraph-shading-widthtext, column
textparagraph-space-aftermeasure
textparagraph-space-beforemeasure
textparagraph-span-columns-countinteger
textparagraph-span-columns-inside-guttermeasure
textparagraph-span-columns-layoutsingle, span, split
textparagraph-span-columns-outside-guttermeasure
textparagraph-span-columns-space-aftermeasure
textparagraph-span-columns-space-after-splitmeasure
textparagraph-span-columns-space-beforemeasure
textparagraph-span-columns-space-before-splitmeasure
textparagraph-stylestring