Keyword highlight

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

Moderators: Alexander Halser, Tim Green

Post Reply
jrhaddad
Posts: 20
Joined: Tue Feb 09, 2010 7:44 pm

Keyword highlight

Unread post by jrhaddad »

Hello,

Is there a way in H&M to highlight keywords in the text like shown in the attached screenshot?


Thanks!

Jean-Robert
You do not have the required permissions to view the files attached to this post.
User avatar
Tim Green
Site Admin
Posts: 23189
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Keyword highlight

Unread post by Tim Green »

Hi Jean-Robert,

You could define a text style that displays text with a background color but not with padding or an outline. Those can only be defined for paragraphs.

Also, if you were thinking of highlighting the keywords automatically that isn't currently supported. You would have to format them manually in each topic. You could do this in HTML WebHelp with a post-processor that you would have to program. It would scan all your topic files and apply the formatting to the keywords on the basis of a file containing all the keywords you want to highlight. Theoretically you could also do it with JavaScript -- it would then scan every topic file when it was opened (again using a keyword list that you would have to generate) and apply the formatting on the fly. But that would involve a lot of processing overhead and I wouldn't really recommend it.
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.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: Keyword highlight

Unread post by Simon Dismore »

I wonder what these "keywords" are supposed to represent? Topic and popup links can be styled with borders, e.g.

Code: Select all

<style>
   a.topiclink {
     background: #cde;
     background-clip: padding-box;
     border: 1px solid #6ae;
     border-radius: 4px;
     padding: 0px 2px 0px 2px;
     color: #07e;
     text-decoration: none;
   }
   a.topiclink:hover {
     background: #6ae;
     border: 1px solid #07e;
     color: #fff;
   }
   </style>
You do not have the required permissions to view the files attached to this post.
jrhaddad
Posts: 20
Joined: Tue Feb 09, 2010 7:44 pm

Re: Keyword highlight

Unread post by jrhaddad »

The keywords are in fact just source code, class names, etc. that I want to highlight in a nice way in the text to make it easier to read. Simply using a different color or color background does not have the same effect.

I don't need links from the text, only a style that surrounds the text with rounded boxes. The example you provide looks interesting. Could I simply define that as new style and apply that style to some text?

Thanks!
User avatar
Tim Green
Site Admin
Posts: 23189
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Keyword highlight

Unread post by Tim Green »

jrhaddad wrote:I don't need links from the text, only a style that surrounds the text with rounded boxes. The example you provide looks interesting. Could I simply define that as new style and apply that style to some text?
That isn't possible directly, unfortunately, and that is why I didn't suggest it. This is because you can't define borders, padding and rounded corners for text styles from within Help & Manual.

However, if you only need this in HTML-based outputs you could still achieve this in your output. You would first define a text style with a simple background color in Help & Manual and apply that text style to the keywords that you want to display like this. Let's assume that this style is called "keyword_hl" for "Keyword Highlight".

IMPORTANT: No spaces in the style name for this!

Then you need to edit your topic page template and add the CSS for the additional style attributes. You must edit in your project if you are not using a skin, and in the .hmskin file if you are using a skin. You will need to copy the .hmskin file to your project folder to edit it if you are using one that is stored in the Help & Manual program directory. After editing, you will then need to select the edited version to publish your project.

Open the .hmskin or project file in Help & Manual. Then in Project Explorer on the left navigate down to Configuration > HTML Page Templates > Default.

IMPORTANT WARNING: Don't switch to the simple layout mode tab in skins with edited source code! Doing this will replace your edited version with the default template and delete your changes. You will be warned if you try to do this, and this is a warning you should take seriously. This is particularly important when editing pre-designed skins, as switching to simple mode there will delete all the custom code and make the skin unusable.

Locate a <style type="text/css">... </style> block inside the <head> ... </head> block. If one does not exist add it directly before the closing </head> tag, like this:

Code: Select all

<style type="text/css">

</style>
</head> 
You will then enter the style code below between the two style tags. If a style block already exists, add your code to the end of it, directly before the closing </style> tag.

Since your style is called keyword_hl it needs to be referenced in the CSS as span.f_keyword_hl because of the way that Help & Manual manages text styles in the output. You can then use Simon's style definition for it like this:

Code: Select all

<style type="text/css">
span.f_keyword_hl {
     background: #cde;
     background-clip: padding-box;
     border: 1px solid #6ae;
     border-radius: 4px;
     padding: 0px 2px 0px 2px;
     color: #07e;
     text-decoration: none;
   }
  span.f_keyword_hl:hover {
     background: #6ae;
     border: 1px solid #07e;
     color: #fff;
   }
</style>
</head> 
Note that you won't see the formatting in the Help & Manual editor, only in the HTML-based output after publishing.
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.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: Keyword highlight

Unread post by Simon Dismore »

Thanks Tim, this has been a useful thread for me to get my thoughts clear. I'd tweak the solution in two ways before recommending it for production, see below.
- Simon

1. In my original answer, the inverted colors when hovering were intended purely for hyperlinks. I don't underline links by default so I need to distinguish the hover state to feed back that the target is a link. Hovering over an unlinked word shouldn't change anything.

2. My technique of inverting links when they are hovered over can't be achieved without hard-coding colors (or relying on non-portable techniques). But hard-coded colors aren't good practice because colors should be set by styles within Help & Manual as far as possible, not hidden away in hand-coded CSS buried in a template or skin.

So I'd simplify the styling as follows:
  • Aim for a general method of drawing rounded borders that doesn't depend on whether the content is a link.
  • Hard-code as little as possible, in this case the border color, margins and thickness but not the text foreground and background colors.
  • To keep links looking clean when they are bordered, hide the link underline by default, but show it when hovering.

Code: Select all

   /* draw a box around everything styled with keyword_hl in Help & Manual */
   /* the text and background colors will be whatever were defined in Help & Manual */ 
   .f_keyword_hl {
     background-clip: padding-box;
     border: 1px solid #CCC;
     border-radius: 4px;
     padding: 0px 2px 1px 2px;
   }
   /* within boxes render link anchors without underlines except when hovering */
   /* the default link and visited link colors are not overridden in this example */
   .f_keyword_hl a { text-decoration: none; }
   .f_keyword_hl a:hover { text-decoration: underline; }
Because the styling doesn't depend on .topiclink, .weblink etc., it is quite general. If you create keyword_hl with a monospaced font and light gray (#F5F5F5) background, when you apply it to unlinked content the result will be similar to jrhaddad's original sample. When you apply it to linked content, it will be colored as a link and underlined when hovered over, like this:
H&M-generalised-highlight-with-custom-css-anim.gif
The only problem is that I can't work out how to create this style within Help & Manual without embedding the font details. Is that possible?
You do not have the required permissions to view the files attached to this post.
User avatar
Tim Green
Site Admin
Posts: 23189
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Keyword highlight

Unread post by Tim Green »

Hi Simon,

I agree that the hovering shouldn't be included -- I just added that as an extra that can easily be deleted. All that is necessary is to remove the span.f_keyword_hl:hover { ... } section. For the rest, I think you're making it a little more complicated than necessary. Since these aren't links they really just need to be formatted; the rounded corners work just fine when the text isn't a link; and no embedded fonts are needed here. And even if you need a mouseover, the :hover pseudo-class is now a standard part of the HTML5 spec and works fine on all elements in modern browsers.
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.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: Keyword highlight

Unread post by Simon Dismore »

Tim Green wrote:no embedded fonts are needed
Sorry, I didn't mean 'embedded'. What I should have asked was...

When I create a new named style in the H&M Editor, is it possible to avoid specifying the font family and size? In Microsoft Word that would be called a 'character' style (e.g. "subtle emphasis"). Word lets me apply character styles to phrases within paragraphs of Normal, Heading1 etc without overriding their font-family and font-size. If I change the entire paragraph style in Word, any character styling in the paragraph doesn't get overridden. The idea is that styles can be added together. Does Help & Manual support that in any way?

Thanks
User avatar
Tim Green
Site Admin
Posts: 23189
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Keyword highlight

Unread post by Tim Green »

Hi Simon,
Simon Dismore wrote:When I create a new named style in the H&M Editor, is it possible to avoid specifying the font family and size?
If you create a named text style and then select "Reset Style" only the font size and nothing else will be stored in it, but you can't eliminate that at the moment as far as I can see. :?
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.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: Keyword highlight

Unread post by Simon Dismore »

Tim Green wrote:only the font size and nothing else will be stored in it, but you can't eliminate that at the moment as far as I can see. :?
It seems to be an "undocumented feature" in the WebHelp compilation process. As far as I can see, a new character style is stored in the source .hmxp file without any font family or font size. But when the default.css file is generated, font-size: 10pt; font-family: Arial; are added automatically.

This behavior might be a bug or just defensive programming (Arial, for goodness sake!) but I suppose it would be unwise to remove it in case it exposes other issues. I'll drop off this thread now :cry:
User avatar
Tim Green
Site Admin
Posts: 23189
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Keyword highlight

Unread post by Tim Green »

Hi Simon,

Update, after discussing this with Alex:

You can't have an empty style in Help & Manual because HM can't "use" an empty style. It always needs a full definition, with font face, size, color, style etc. If a style is based on another it can be technically empty, because it gets all its data from its parent. If it is independent (no "based on") then it uses the defaults of "Arial 10, text color, not bold/italic/underline". However, only Arial 10 is explicitly defined. All other values are null and are not explicitly stored.
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.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: Keyword highlight

Unread post by Simon Dismore »

OK, I get it. Thanks for checking :-)
Post Reply