Indent from RTF OK in HM4 editor but wrong in CHM

Please post bug reports for earlier versions of Help & Manual (3 and 4) here, along with reports for TNT.

Moderators: Alexander Halser, Tim Green

Post Reply
Robert McConnell
Posts: 27
Joined: Thu Nov 22, 2007 4:23 pm

Indent from RTF OK in HM4 editor but wrong in CHM

Unread post by Robert McConnell »

I've found what appears to be a bug that does not seem to have an obvious workaround.

The manual for our product includes examples of scripts whose indentation is important for clarity. Indentations are created by inserting 0, 2, 4, etc spaces at the beginning of each line. These scripts originate as simple text files, first imported into Word. When the Word .rtf file is then imported into HM4 the indentation, appears correct in in the editor, and is usually correct in the resulting .chm file. The one exception that I've found is that when the indentation is 2 spaces in the .hmx file it is incorrectly reduced to 0 spaces in the .chm file. Larger values of indentation used all appear correctly.

Creating a special style and editing thousands of lines of script code is not an attractive option in this case.


Attached files in hmbug_2.zip:
hmbug_2a.gif correct format as viewed in bug2.hmx file
hmbug_2b.gif. incorrect format as viewed in bug2.chm file
bug2.hmx source file (see "Lesson 2")
bug2.chm compiled output (see "Lesson 2")
You do not have the required permissions to view the files attached to this post.
User avatar
Tim Green
Site Admin
Posts: 23156
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Unread post by Tim Green »

Hi Robert,

This is not a bug -- you are running into a standard problem with the way HTML renders space characters and you just need a little more information on the way H&M handles this. If you have a look at the HTML code with View Source in the CHM file (just right-click for the context menu) you will see that the spaces are there, they are just not being rendered.

H&M is set up to handle code indents with spaces automatically, but in normal paragraphs with word wrap activated you must use at least three spaces. H&M will then start and end the space block with a normal space and place non-breaking space characters between them, like this:

Code: Select all

Three spaces:
   Text following the spaces
Six spaces:
      Text following the spaces
These combinations are rendered correctly in HTML and will also break if the line must break. It doesn't work with two spaces because then you would get spurious spaces at the beginning of the next line if the line ever had to break -- that's why you must have at least three spaces.

However, all this only applies if you are using "normal" paragraphs with word wrap turned on. If you turn word wrap off (or define a style with word wrap off) ALL spaces are rendered as non-breaking spaces -- that is how word wrap gets turned off in HTML. This means you have two possible solutions:
  • If you are sure that your lines will never need to break in this application just define a style with word wrap turned off and apply it to all the text formatted like this. Then your 2-character indents will also work.

    Since this is imported formatted text you will need to select the text to apply the style. You can define the style easily by clicking in a sample paragraph and selecting Format > Create Style from Selection, after which you will have to edit the style definition to turn word wrap off in the paragraph settings.
  • Alternatively, if you don't want to use word wrap, you will have to do increase your indent sizes so that your initial indents all have a minimum of three spaces. If you need to do this in the entire project it will probably be easier to do in XML in a text editor, which you can do if you have the Pro version of Help & Manual. To do this compile to XML with File > Compile > XML, selecting the option to export all topics to a single file. Then open the main XML file in a text editor and do the search and replace operations. After that you can import back to your project with File > Import > XML, selecting the option to replace existing topics. You can preview the XML code you need to replace in Help & Manual by selecting the XML Source Code tab in any topic.
Robert McConnell
Posts: 27
Joined: Thu Nov 22, 2007 4:23 pm

Unread post by Robert McConnell »

Tim,

Many thanks for the very complete explanation. Who would have thought that changing word wrap would have affected indentation at beginning of paragraph? But that's the fix I'll use.

-rob
Post Reply