Glyph – Using Glyph programmatically

Besides using Glyph from the command line, you can also use it straight from your code. Glyph’s public API is simple and can be used to:

  • Retrieve and update configuration settings (using Glyph[] and Glyph[]=)
  • Filter text to HTML (using Glyph#filter)
  • Compile Glyph source files into HTML or PDF files (using Glyph#compile)

That’s pretty much it. Of course, both the filter and compile method cause Glyph to run in lite mode, so the same limitations apply.


It is possible to specify some flags (or "modes") to make Glyph behave slightly different than normal, as shown in the following table (by default, none of these is used).

Name Writer Method Reader Method Description
Test Mode Glyph.test_mode= Glyph.test? Used internally by the rake spec task to run Glyph's specs.
Library Mode Glyph.library_mode= Glyph.library? If enabled, the compile command command will raise exceptions instead of printing errors on the screen. Enabled by the Glyph.compile command.
Debug Mode Glyph.debug_mode= Glyph.debug? If enabled, additional diagnostic information (such as backtraces or macro values) will be displayed. Enabled by specifying the debug switch when running a Glyph command.
Lite Mode Glyph.lite_mode= Glyph.lite?

Used to compile single files. Enabled by:

  • The Glyph.compile and Glyph.filter methods.
  • The compile command, if at least one parameter is supplied.
Safe Mode Glyph.safe_mode=

If enabled, the following macros cannot be used and will return an error: