Skip to main content
Participant
August 28, 2016
Question

Replacing a Style or Paragraph Tag with Another

  • August 28, 2016
  • 1 reply
  • 289 views

Hi,

I am trying to find the API to set the style in RoboHelp Script. In the Clean Project Example (as in the following code snippet), it shows how to find a undefined style and remove that style. In this case, instead of token.removeAttribute("style"), is it possible to set a style, for example, a paragraph tag, say "body". Also, is it possible to find a paragraph tag, say "Normal", and replace it with "body" paragraph tag.

if(token.tokenType == RoboHelp.TokenType.TOKENTAG)
{
//Does this token have style attribute?
if(token.getAttribute("style") != "")
{
//This token has a style attribute. Now remove the style attribute.
token.removeAttribute("style");
}
}

Thanks.

This topic has been closed for replies.

1 reply

Willam van Weelden
Inspiring
August 29, 2016

You want to set a style name? In that case: (note: I didn't run/test this, but it should at least point in the right direction)

if(token.tokenType == RoboHelp.TokenType.TOKENTAG && token.hasAttribute("style") == true) {

   token.removeAttribute("style");

   token.setAttribute("class","myStyleName");

}

The above will assign the class 'myStyleName'. You'll, of course, want to check the type of tag and whether you need to assign the style.

Something that I have been having fun with: you'll have to save before closing the TokenManager. Otherwise you'll be wondering why the script won't work. Embaressed to say I've forgotten this more than once...

tokens.save();//Save changes

tokens.close();//Close the TokenManager or you'll run out of memory