Remove Text Highlighting - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Remove Text Highlighting

When using the text highlighter on the contents of a rich text field, or on the contents of a view in the designer, InfoPath insert a font element around the text being highlighted, setting the background color to the selected highlight color.

The following code block shows the XHTML of two paragraphs in a rich text field. The first paragraph has no highlight, while the second one has a yellow highlight.

<div xmlns="http://www.w3.org/1999/xhtml">This text has no highlight.</div>
<div xmlns="http://www.w3.org/1999/xhtml"><font style='BACKGROUND-COLOR: #ffff00'>This text has a yellow highlight.</font></div>

Adding a highlight is as simple as selecting text and then choosing the highlight color; but removing the highlight is not as obvious. Microsoft Word has a very definite choice of None among its highlight colors (as shown in Figure 1) while InfoPath does not.


Figure 1. InfoPath (left) provides more highlight colors than Word (right), but does not provide the option for ‘None’.

Although not obvious, InfoPath also provides a None choice: the white highlight color. If you select text with a highlight color and then choose the white highlight color, InfoPath will remove the font element from the XHTML contents of the rich text field. Our previous code block would now look like this:

<div xmlns="http://www.w3.org/1999/xhtml">This text has no highlight.</div>
<div xmlns="http://www.w3.org/1999/xhtml">This text has a yellow highlight.</div>

But there is a catch. The white highlight color will only remove the highlight when the entire highlighted section is selected, otherwise it will insert a font element to set a white background color. For example, if instead of selecting the entire second paragraph and setting the highlight color to white, we only select a portion of the highlighted text (whether that be at the start, middle, or end of the paragraph), the resulting XHTML will look something like this:

<div xmlns="http://www.w3.org/1999/xhtml">This text has no highlight.</div>
<div xmlns="http://www.w3.org/1999/xhtml"><font style='BACKGROUND-COLOR: #ffff00'>This <font style='BACKGROUND-COLOR: #ffffff'>text has</font> a yellow highlight.</font></div> </my:field1>

The results of this behavior would be more obvious if the background color of the control or view were set to something other than the default white color.

So how do you completely remove the highlight color from a portion of the highlighted text rather than change it to white? The solution is to use another less obvious option, which is the keyboard shortcut for removing text formatting. To use the keyboard shortcut, select the desired text, and then press Ctrl+Space to remove the formatting. Although this works, if you had other formatting besides just the highlight color, you might end up with unexpected results. This approach is fully described in Quickly Remove Text Formatting.

©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Published Jun 17 2005, 04:41 PM by Greg Collins
Filed under:

Comments

No Comments
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.