May describe unreleased features ยท Switch to current
release
4.2
ยท For shortcuts, type ?
Embedding web fonts in HTML output
A custom plug-in can be created to generate HTML output that uses custom fonts for enhanced typographic
features, extended character sets or a unique corporate identity.
About this task
This scenario walks through the process of creating a very simple plug-in
(com.example.html5-webfont) that creates a new transformation type:
html5-webfont.
The html5-webfont transformation includes a custom CSS file and sets five parameters to
integrate font links and a custom stylesheet in the generated HTML5 output. These parameter settings make the
following changes:
Specify a file that links to the font from the document head with args.hdf.
Specify the css subfolder of the plug-in as the source directory for custom CSS with
args.cssroot.
Specify the name of the custom CSS file with args.css.
The value of this parameter tells DITA-OT to use the custom.css file provided by the
plug-in.
Ensure that the CSS file is copied to the output directory by setting args.copycss to
yes.
Set the destination path for CSS files in the output folder with args.csspath.
CSS files are copied to the root level of the output folder by default. Setting this parameter places CSS
files in a dedicated css subfolder.
All five parameters are set in the Ant script (build_html5-webfont.xml).
Procedure
In the plugins directory, create a directory named
com.example.html5-webfont.
In the new com.example.html5-webfont directory, create a plug-in configuration file
(plugin.xml) that declares the new html5-webfont transformation and
its dependencies.
Note:
This plug-in will extend the default HTML5 transformation, so the <require>
element explicitly defines org.dita.html5 as a dependency.
In the com.example.html5-webfont directory, create a subdirectory named
include.
In the new include subdirectory, create a file named
webfont.hdf.xml with your custom font links.
This example uses the
Noto Sans font. You can use multiple fonts by creating additional
<link> references in this file. The division wrapper will be discarded when
generating HTML files, and the contents will be inserted into the <head> element of
each page.
In the com.example.html5-webfont directory, create a subdirectory named
css.
In the new css subdirectory, create a file named custom.css with
the stylesheet rules that apply the custom font-family to the desired elements.
This example uses
Noto Sans for all body content. In practice, you would normally use different fonts
for headings, body content, tables, etc. by creating additional rules in your CSS file.
In the com.example.html5-webfont root directory, add an Ant script
(build_html5-webfont.xml) to define the transformation type.
Results
Tip:
The files for this sample plug-in are included in the DITA-OT installation directory under
docsrc/samples/plugins/com.example.html5-webfont/ and on
GitHub.
The plug-in directory has the following layout and files: