Home Forums General XMetaL Discussion Highlighting and coloring text Reply To: Highlighting and coloring text

mag3737

Reply to: Highlighting and coloring text

Hi Andreas,

You could do this with some script.  The useful API is ContainerStyle(), which is a property of the Selection/Range object.  ContainerStyle is a string containing CSS style declarations — a sequence of property:value pairs separated by semicolons — the stuff that would be between the { } in a CSS descriptor.  When you set this property, it applies those styles to the container of the current selection or range.  They are added to any existing styles from the stylesheet already being used.

E.g. The following line of code would apply a yellow background to the container of your current selection:
[code]Selection.ContainerStyle = “background-color:yellow” [/code]

Styles applied with this method will last as long as the document remains open in either Normal or Tags On view.  If you switch to Plain Text view, or close and reopen the document, all of these script-applied styles are wiped out (back to the base CSS stylesheet).

The second part of the problem is when/how you should execute this script.

You could, for example, put this code in a user macro that used a range object to traverse all the nodes in turn, grabbed the “color” attribute value of each one, and set this property.  E.g. you could name the macro something like “Refresh all fontColor elements”.

More likely, you would want the background colors to change automatically whenever the user adds a element or changes an attribute value.  There are several places where you might/might not need to repeat the script logic that applies these styles, including:  On_Insert script for whenever the element is added; On_Update_UI macro that detects if changes have been made to a color attribute; and On_View_Change macro where you can detect if the user is “changing back” from Plain Text View.

Reply

Products
Downloads
Support