Ephox EditLive! for XML and CSS

Introduction

Ephox EditLive! for XML provides support for the use of Cascading Style Sheets (CSS) to enforce formatting standards easily by separating content from formatting. Styles can be used within XHTML sections of an EditLive! for XML document. Styles will also be used to render text within EditLive! for XML. Styles can be specified via an external, linked style sheet, through an embedded style sheet or through inline style information (e.g. in a <SPAN> tag). This article assumes the reader is familiar with the concept of using Cascading Style Sheets. If you would like to learn more about CSS before reading this document, please visit the W3C's Introduction to CSS.

Style Types

EditLive! for XML provides several methods of adding style information to a document. Furthermore, EditLive! for XML recognizes style information and populates the style drop-down list box accordingly. EditLive! for XML can apply styles both as inline styles and block styles. Block styles are applied to an entire XHTML element such as a <P> tag whereas inline styles are applied to a section of text within a XHTML element.

Specifying Block Styles

The way in which styles are specified within a style sheet affects the way they can be applied within EditLive! for XML. Style classes which are directly associated with a block tag can only be applied to a block tag. These styles are designated by a ¶ symbol on the styles drop down in EditLive! for XML. A block style which defines that paragraph text should be blue can be defined as follows:

p.blue{color: blue}

Specifying Inline Styles

Inline styles in EditLive! for XML are applied using the <SPAN> XHTML element. Thus, to define a style which can only be used inline it should be defined as a class to be used with the <SPAN> tag. These styles are designated by an a mark on the styles drop down in EditLive! for XML. An inline style which would specify text that is to have a red color would be as follows:

span.redtext{color:red} 

Specifying a Block and Inline Style

Finally, it is possible to define a style class which may be used as both an inline and block style. These styles appear twice on the EditLive! for XML styles drop down, once marked with the ¶ symbol and again with an a mark. A style class which could be applied on both block and inline tags to change the text color to green is as follows:

.green{color:green}

Adding Styles to EditLive! for XML

Style information for EditLive! for XML can be provided in the following ways:

  • The XML configuration file of EditLive! for XML may include style information in a couple of ways. Note that, with the exception of styles defined inline, style information specified through the use of the XML configuration file takes precedence over style information specified in any other way.

  • Microsoft Word Styles can be imported from a Microsoft Word document using simple copy and paste. This action is permitted using the <wordImport> element.

It should be noted that EditLive! for XML's CSS support complies with the W3C CSS precedence rules. Thus inline styles take precedence over an embedded style sheet. Furthermore the styles listed in an embedded style sheet take precedence over those from an external style sheet. Finally, when multiple external style sheets are used style sheets listed last will have precedence if there is any conflict between style sheets.

Important

If embedded styles are specified using the XML configuration file, the embedded styles specified will be the only embedded styles to exist in the XHTML.

For example, if the configuration file specifies H1{font-size: 10;} and then the styles property for an instance of EditLive! for XML specifies H1{font-size: 20} H2{font-size: 15}, then the resulting embedded styles for the XHTML will still only be H1{font-size: 10}.

Inline styles however will still exist for any single tag specified.

For example, if the XHTML specified with an instance of EditLive! for XML contains <span style="color: yellow">Yellow Text</span> then this style will still exist for the specified tag.

Including Styles via the Configuration File

Linking to an External Style Sheet

EditLive! for XML can be configured to use external style sheets by specifying a value with the <link> element in the configuration file.

When EditLive! for XML links to multiple style sheets, the last style sheet added will have priority if there is a conflict with an earlier style sheet.

For example, if stylesheet1.css defined H1 as:

 H1 { font-family: Arial,Helvetica,sans-serif; font-size: 24pt; }

and another style sheet linked after stylesheet1.css 1, defined H1 as:

 H1 { font-family: Arial,Helvetica,sans-serif; font-size: 48pt; } 

the value of stylesheet1.css for H1 would be overridden by the value given in the second style sheet (i.e. H1 would be size 48pt, not 24pt). Hence, the order that style sheets are added is important and will effect how the HTML is formatted.

Defining an Embedded Style Sheet

Through the <style> element of the EditLive! for XML configuration file an embedded style sheet can specified. Styles listed in a style sheet embedded via the XML configuration file take precedence over styles otherwise defined. The following would configure EditLive! for XML to use the provided embedded style sheet. The embedded style sheet used for this example would implement a mixture of inline and block styles.

<editLive> 
  <document> 
    <html> 
      <head> 
        <style> 
          <!-- 
          p.blue{color: blue} 
          span.red{color: red} 
          .green{color: green} 
          --> 
        </style> 
      </head> 
    </html> 
  </document> 
  ... 
</editLive>

Importing Styles from Microsoft Word

Unless the styleOption attribute of the <wordImport> element in the configuration file is set to clean, styles may be imported from Microsoft Word. This action is performed by copying text from Microsoft Word and selecting paste in EditLive! for XML. When styles are imported in this manner they are added to the embedded style sheet of the document in EditLive! for XML. If a style of the same class already exists in EditLive! for XML it will take precedence over any style from Microsoft Word.

When copying text from Microsoft Word, users will be prompted with a dialog box asking whether to copy the text's styles as embedded styles or inline styles. In cases where EditLive! for XML has used an XML configuration file specifying embedded styles, users should copy text and styles from Microsoft Word using inline styles. The reason for this is that embedded styles specified in the XML configuration file override all other embedded styles specified for the XHTML, including styles copied from Microsoft Word.

Note

Style information cannot be imported from Microsoft Word when using EditLive! for XML. It is recommended that the styleOption attribute of the <wordImport> element in the configuration file is set to clean within the configuration for EditLive! for XML.

Using the _styles HTTP Post Attribute

As documented in Retrieving Content, both the HTML content and the CSS styles contained in an instance of EditLive! for XML can be sent through a HTTP Post. When a form containing an instance of EditLive! for XML is submitted, a hidden field containing all style information for the document is also created and posted with the form data. This hidden field will be called ELJAppletName_styles, where ELJAppletName is the name specified by the developer when the EditLive! for XML instance was created.

The page listed as the action to receive the HTTP Post could then contain controls to assign the styles information to a variable, which could then be saved to a back-end database.

For example, where the page sending the HTTP Post has generated a hidden field called ELJAppletName_styles, containing the styles information :

VB Scripting

<%
  Dim stylesInformation = Request( "ELJAppletName_styles" )
%>

JSP Scripting

<%
  String stylesInformation = request.getParameter("ELJAppletName_styles");
%>

Populating the Styles Drop-down List Box

When style information is added to EditLive! for XML then style information will be added to the style drop-down list box. This means that users can quickly and easily access style information. For example, if a style sheet defined the following styles:

h1{color: yellow} 
p.blue{color: blue}
span.red{color: red}
.green{color: green}

Then .blue and .red and .green would appear as options within the styles drop-down list box giving users easy access to this style information. Also the Heading 1 style would have yellow colored text.

In the EditLive! for XML styles drop down block styles are depicted with a ¶ symbol next to them and inline styles are depicted with an a symbol next to them. Thus, the style drop down for the above example may appear as follows:

Heading 1

.blue

.red a

green

.green a

Note that the .green class appears twice as it can be applied as both an inline and a block style. For more information please see the Specifying Inline and Block Styles section of this article.

Getting Styles from EditLive! for XML

There are three ways to extract the styles information from an instance of EditLive! for XML:

  • getStyles runtime method for an instance of EditLive! for XML. For more information on how to retrieve styles in this manner please see the getStyles runtime API property in this SDK.

  • Accessing the _styles HTTP Post Attribute. Information on how this data is sent and can be retrieved is documented in section above titled Using the _styles HTTP Post Attribute.

  • getDocument runtime method for an instance of EditLive! for XML. This method returns the entire XHTML Document, including the embedded styles in the <head> tag. For more information on how to retrieve the entire XHTML document, see the getDocument runtime API property in this SDK.

Summary

EditLive! for XML provides excellent support for implementing cascading style sheets (CSS). Style information can be used with an EditLive! for XML document in a number of ways; as an externally linked style sheet, as an embedded style sheet or importing content from Microsoft Word. This style information will then be used by EditLive! for XML to populate the styles drop-down list box giving users easy access to style information.

See Also