SOLVED: Setting HTML fallback fonts using HelpNDoc and it's not pretty

We've recently come across a problem with setting a failback font for the HTML output of HelpNDoc.

By default HelpNDocs styles are configured to use Default Font this is built into the application as Arial and cannot be changed.


Screenshot of HelpNDoc's default style
HelpNDoc's default style


By default HelpNDoc's Normal style is set to Default Font as seen above. You can change this font but only to a single font. 

Setting the font to something like 'Segoe UI', 'Calibri' will appear to work but fail silently on output.

Screenshot of HelpNDoc's normal style
HelpNDoc's style editor

If you set the font on the content to - for example Calibri this will set the font correctly in Word, CHM, etc however for the HTML content the following will occur.

The main-content class will remain as the system default of Arial with some fallbacks automatically added. The Calibri font will then be set over and over again on all paragraphs that use the Normal style.

This makes it impossible to override the font on main-content without overriding main-content * which will then override all of your custom styles.

Realistically HelpNDoc should be updating the main-content style with your specific Calibri font and not setting the font on the span tags.

Interestingly enough if you do not set the font for Normal then the main-content style remains the same and the font is not set for all of the spans that use Normal.

<div class="main-content">

    <p class="rvps2">
        <span class="rvts6">Some normal content.</span>
    </p>
    <p class="rvps4">
        <span class="rvts11"># Create the new item.</span>
    </p>
</div>


.main-content, .main-content table span.rvts0 /* Normal text */
{
 font-size: 10pt;
 font-family: 'Arial', 'Helvetica', sans-serif;
 font-style: normal;
 font-weight: normal;
 color: #000000;
 text-decoration: none;
}

span.rvts6
{
 font-family: 'Calibri';
}


span.rvts11
{
 font-size: 9pt;
 font-family: 'Lucida Console', 'Monaco', monospace;
 color: #006400;
}


Workaround 1 - Don't Set the Font in Styles
You can workaround the issue by removing the font from Normal and leaving the defaults.

It's then possible to set a style override of the Normal font in each template.

Screenshot of setting a specific font
Setting a specific font

You can then use your template to overwrite the font in the main-content style.



Workaround 2
It's possible to run a PowerShell script to correct the CSS file with fallback fonts.

# Update the HelpNDoc hnd.content.css with fallback fonts.
$cssPath = "C:\temp\someproject\html\css\hnd.content.css"
$cssContent = Get-Content $cssPath -Raw
$cssContent = $cssContent -replace "font-family:\s*'Calibri';", "font-family: 'Calibri', 'Segoe UI', 'Arial', sans-serif;"
Set-Content -Path $cssPath -Value $cssContent 


It is possible to run this as part of the build using HelpNDoc's build actions.

However these are only available on Ultimate edition - so without this edition you'll need to run the commands manually after build.









Comments

Popular posts from this blog

SOLVED: Exchange Online Management PowerShell Connect-ExchangeOnline bug "A window handle must be configured. See https://aka.ms/msal-net-wam#parent-window-handles"

Windows Server 2016, 2019, 2022, Windows 10 and Windows 11: Date and time "Some settings are managed by your organization".

get-windowsfeature : The given key was not present in the dictionary