Configure CSS stylesheet used by editor
As a programmer, I need a mechanism to attach a CSS style to the editor so that the edited content resembles my website.
As a programmer, I want to configure the CSS style of the rich text editor from a single place.
As a programmer, I want to use the CSS rules both when editing and displaying (rendering) the content edited using Canvas Editor.
As a programmer, I want to override the colors in the CSS document with the colors from the Material UI theme.
You can configure the Canvas Editor rich text editor to use a custom CSS style. The CSS style is configured via the IOC container.
For this, the "CSS_DOCUMENT" property of the IOC container needs to be set:
The CSSDocument class has the following declaration:
The cssText parameter used when initializing the CSSDocument class must contain CSS rules parsable by the CSS engine used by Canvas Editor. Only a subset of CSS properties is parsed, and only a subset of rule values is renderable by Canvas Editor.
Supported CSS Properties:
| Property Family | CSS Property | Format | Parsable | Functionality | 
|---|---|---|---|---|
| Background | background background-color  | css_color | Yes | Block elements only | 
| Border | border border-top border-right border-bottom border-left  | css_length css_border_style css_color | Yes | Block elements only | 
| border-color, border-top-color, border-right-color, border-left-color, border-bottom-color | css_color | Yes | Block elements only | |
| border-style, border-top-style, border-right-style, border-bottom-style, border-left-style | dotted | dashed | solid  | Yes | Block elements only | |
| border-width, border-top-width, border-right-width, border-bottom-width, border-left-width | css_length | Yes | Block elements only | |
| border-collapse | collapse | separate  | Yes | Table only, forced to collapse | |
| Cursor | caret-color | css_color | Yes | Block elements only | 
| caret-shape | bar | block | underscore  | Yes | Block elements only | |
| Text | color | css_color | Yes | Yes | 
| font | font_size font_family font_style font_weight line_height | Yes | font-variant is ignored | |
| font-family | string, e.g.: "Roboto Mono" | Yes | Google fonts only | |
| font-weight | css_font_weight | Yes | 400 and 700 works, rest is 400 | |
| font-size | css_length | Yes | Yes | |
| font-style | italic | oblique | normal  | Yes | Yes | |
| line-height | css_length | Yes | Yes | |
| text-align | css_text_align | Yes | justified renders as left | |
| text-decoration | none | underline | line-through | overline | blink  | Yes | "blink" not implemented | |
| text-decoration-color | css_color | Yes | ||
| text-decoration-line | none | underline | overline | line-through  | Yes | Inline elements only | |
| text-decoration-style | solid | double | dotted | dashed | wavy | spelling-error  | Yes | Only solid, dotted and dashed work | |
| vertical-align | sub | bottom | super | top | middle | center | baseline | text-bottom | unset  | Yes | CSS length format not implemented (eg: vertical-align: 20px) | |
| Margin | margin margin-top margin-right margin-bottom margin-left  | css_length | Yes | Block elements only | 
| Padding | padding padding-top padding-right padding-bottom padding-left  | css_length >= 0 | Yes | Block elements only | 
| Dimensions | width height  | css_length >= 0 | Yes | Img and Table only | 
Supported HTML Tags:
Block Elements:
- p
 - h1
 - h2
 - h3
 - h4
 - h5
 - h6
 - ul
 - ol
 - li
 - table
 - tr
 - td
 - pre
 - blockquote
 - div (converted to P)
 
Inline Elements:
Canvas Editor supports the following inline HTML tags:
- img
 - br
 - a
 - abbr
 - acronym
 - b
 - big
 - cite
 - code
 - del
 - dfn
 - em
 - i
 - ins
 - kbd
 - label
 - q
 - s
 - samp
 - small
 - span
 - strong
 - strike
 - sub
 - sup
 - time
 - tt
 - u
 - var
 
All other HTML tags are either ignored or converted to other supported types.
Supported CSS Selectors in Canvas Editor
- Universal selector * (e.g., * { ... })
 - Tag selector (e.g., p { ... })
 - @font-face { ... }
 
All other types of CSS selectors are not implemented.
CSS Inheritance
Everything declared in the universal selector * functions as the default value for any unspecified value in other selectors. For example, in the following CSS document:
- The color of the p tag is "red" because it is not specified in the p selector.
 - The color of the h1 tag is also red because the h1 tag is not declared in the CSS document.
 
@font-face CSS Rule
In a CSS document, you can use multiple @font-face blocks. The @font-face blocks indicate to the editor which fonts to automatically load from Google Fonts.
In this @font-face block, the significance of the rules is as follows:
The "Roboto" font is automatically loaded from Google Fonts.
All elements using font-family: "sans-serif", "sans", –apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, or Arial will be displayed using the "Roboto" font.
Limitations
- The universal selector * is mandatory in a CSS style supported by Canvas Editor and must contain default values for all CSS properties implemented by the rendering engine.
 - All fonts used by the CSS rules must be declared with the @font-face selector.