You can add custom HTML content in the WebHelp Responsive output by inserting it in a well-formed XML file (or specifying it in a well-formed XHTML fragment) that will be referenced in the transformation (either from an Oxygen Publishing Template or using one of the HTML fragment placeholder parameters). This content may include references to additional JavaScript, CSS, and other types of resources, or such resources can be inserted inline within the HTML content that is inserted in the XML file.
Well-Formedness - If the content of the file is not XML Well-formed, the transformation will automatically convert
non-well-formed HTML content to a well-formed XML equivalent (assuming the
webhelp.enable.html.fragments.cleanup transformation parameter is
set to true).
For example, if the HTML content includes several
<script> or <link> elements, the XML
fragment would have multiple root elements and to make it well-formed, it would be
wrapped it in an <html> element. This element tag will be
filtered out and only its children will be copied to the output documents. Similarly,
you can wrap your content in <head>,
<body>, <html/head>, or
<html/body> elements.
webhelp.enable.html.fragments.cleanup transformation
parameter to false. This will instead cause the transformation to fail if at
least one HTML fragment is not well-formed.${oxygen-webhelp-output-dir} macro to specify their paths relative to
the output
directory:<html>
<script type="text/javascript" src="${oxygen-webhelp-output-dir}/js/test.js"/>
<link rel="stylesheet" type="text/css"
href="${oxygen-webhelp-output-dir}/css/test.css" />
</html>If you want that the path of your resource to be relative to the templates directory, you can use the
${oxygen-webhelp-template-dir} macro.
To copy the referenced resources to the output directory, follow the procedure in: How to Copy Additional Resources to Output Directory.
Inline JavaScript or CSS Content:
<script type="text/javascript">
/* Include JavaScript code here. */
function myFunction() {
return true;
}
</script> <style>
/* Include CSS style rules here. */
*{
color:red
}
</style>If you have special characters (e.g. &,
<) that break the well-formedness of the XML fragment, it is
important to place the content inside an XML comment.
Otherwise, the WebHelp transformation automatically wraps inline JavaScript or CSS content in an XML comment. Also, if the commented content contains constructs that are not allowed in an XML comment, those constructs are escaped.
[Important] XML comment tags (both the start and end tags) must be on lines by themselves. If they are on the same line as any of the script's content, it will likely result in a JavaScript error.
<script type="text/javascript">
<!--
/* Include JavaScript code here. */
function myFunction() {
return true;
}
--/>
</script>
The XML file can use WebHelp macros, which are variables that will be expanded when the content of the HTML fragment file will be copied in the final output.
<script type="text/javascript" src="${path(oxygen-webhelp-template-dir)}/"></script><whc:macro> template
component:<script type="text/javascript">
var outDirPath = '<whc:macro value="${path(oxygen-webhelp-output-dir)}"
xmlns:whc="http://www.oxygenxml.com/webhelp/components"/>';
console.log("The output directory path is:", outDirPath);
</script><whc:macro> element,
you should also include the
xmlns:whc="http://www.oxygenxml.com/webhelp/components" namespace
declaration for the whc prefix. This is necessary for the XML
fragment to be well-formed. ${i18n(string.id)}${param(webhelp.show.main.page.tiles)}${env(JAVA_HOME)}${system-property(os.name)}format-dateTime function
specification.${timestamp([h1]:[m01] [P] [M01]/[D01]/[Y0001])}${path(oxygen-webhelp-template-dir)} wh-macro-custom-path template from
com.oxygenxml.webhelp.responsive\xsl\template\macroExpander.xsl:
<!-- Extension template for expanding a custom path macro. -->
<xsl:template name="wh-macro-custom-path">
<xsl:param name="pathId"/>
<xsl:value-of select="$pathId"/>
</xsl:template> ${map-xpath(/map/title)}${topic-xpath(string-join(//shortdesc//text(), ' '))}${oxygen-webhelp-build-number} <publishing-template>
...
<webhelp>
...
<html-fragments>
<fragment
file="html-fragments/custom-html.xml"
placeholder="webhelp.fragment.head"/>Results: Your additional content will be included at the end of the
<head> element of your output document.
webhelp.fragment.head parameter and set it to
the absolute path of your XML file.Results: Your additional content will be included at the end of the
<head> element of your output document.