Applying a style/highlight to every instance of a word

Please post all questions relating to Help & Manual 6 here!

Moderators: Alexander Halser, Tim Green

Post Reply
Sa Williams
Posts: 7
Joined: Tue Apr 08, 2014 4:48 pm

Applying a style/highlight to every instance of a word

Unread post by Sa Williams »

I'm not sure if this is possible, or whether it should be in the "wishlist", but here goes.

When writing documnets I often use "xxx" to indicate a section I need to come back to. What I'd like to do is retrospectively apply a style or highlight to all occurances of "xxx" so it stands out.

I know how to create a style, but is there an easy way to do this using Find and Replace or somesuch?

Thanks
Kathleen Laughlin
Posts: 66
Joined: Wed Jun 04, 2008 3:47 pm
Location: Cary, NC USA

Re: Applying a style/highlight to every instance of a word

Unread post by Kathleen Laughlin »

Sa, would a variable work for you? They're easy to find in the text.
User avatar
Tim Green
Site Admin
Posts: 23157
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Applying a style/highlight to every instance of a word

Unread post by Tim Green »

Hi Sa,

Search and replace with styles is not currently available. What you can do is define the style that you want to use and assign a keyboard shortcut to it. Then perform a search for the text and apply the shortcut manually every time it is found (it will be selected then).

For future use you can define the pre-styled text for this element as a snippet and insert it whenever you need to use it. To do this select an example of the formatted text as you want to use it, and then select Project > File > Save Snippet and save it in your project folder. To insert it, select the snippet tool and use these settings:
  • From File
  • Copy & Paste
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
User avatar
Mike Linacre
Posts: 103
Joined: Wed Apr 06, 2005 11:12 pm
Location: Chicago
Contact:

Re: Applying a style/highlight to every instance of a word

Unread post by Mike Linacre »

Sa, an immediate work-around.

1. Define the style - xstyle - for your xxx
2. Save your project as uncompressed XML, and also save a compressed XML as back-up.
3. Close the project
4. Use a find-and-replace utility, such as PowerGREP
5. Global replace in the uncompressed project .xml files:
xxx
by
<text styleclass="xstyle" translate="true">xxx</text>
6. Open the uncompressed project in HM.
7. all xxx should have the xstyle
User avatar
Tim Green
Site Admin
Posts: 23157
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Applying a style/highlight to every instance of a word

Unread post by Tim Green »

Hi Mike,
Mike Linacre wrote:Sa, an immediate work-around.
Please don't try this! This will not work correctly - the result will be invalid XML! You cannot just insert a new <text></text> tag block in the middle of another block of text without terminating the text around it too. This is why I didn't suggest using XML source editing to solve this.

To do it correctly you need to get the style reference from the surrounding paragraph and repeat it. For example, suppose you want to add a text style called "Hilite" to two words in this paragraph:

Code: Select all

<para styleclass="Normal"><text styleclass="Normal" translate="true">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. </text></para>
You would need to do this to produce valid XML:

Code: Select all

<para styleclass="Normal"><text styleclass="Normal" translate="true">Lorem ipsum dolor sit amet, </text><text styleclass="Hilite" translate="true">consectetuer adipiscing</text><text styleclass="Normal" translate="true"> elit. </text></para>
This splits the text of the paragraph into three text nodes: two with the style of the surrounding paragraph (before and after your styled words) and the styled words with their own style. Doing this with search and replace is complex, because you need to get all the text node attributes from the surrounding node and repeat them. The example is very simple -- it looks very different when there is a lot of inline formatting as well.
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
Sa Williams
Posts: 7
Joined: Tue Apr 08, 2014 4:48 pm

Re: Applying a style/highlight to every instance of a word

Unread post by Sa Williams »

Thanks for the replies.

I have opted for using Find and Replace for the "xxx" and putting the dialog box right next to the highlight button so there is minimal mouse movement!

I actually had problems creating a style that would JUST colour the background as all styles seem to need a font face, style and size defined. As the text I wanted to highlight was several different sizes, depending what section of the documenet it was in, that wouldn't be appropriate.

I had though of a similar solution to Mike, but had worked out that the <text> tags could not be nested and therefore need to define the font. Seems a shame though...
User avatar
Mike Linacre
Posts: 103
Joined: Wed Apr 06, 2005 11:12 pm
Location: Chicago
Contact:

Re: Applying a style/highlight to every instance of a word

Unread post by Mike Linacre »

Thanks, Tim, for the correction. Apologies, my original global-replace does have unwanted side-effects. The locations of the "xxx" are even more visible than intended. Congratulations to HM programmers that neither HM nor the project crashes!
Post Reply