Glyph - Core Macros

add

Adds two or more integers together.

Example: add[2|5|7]

alias

Creates a macro alias.

Example: alias[s|section]

Parameters

Parameter Description
0 The name of the alias.
1 The name of an existing macro.

and

Conditional and operator, to be used with the condition macro.

Example: ?[and[true|false]|This is never displayed.]

Parameters

Parameter Description
0 The first expression to test
1 The second expression to test

attribute

Returns the value of the specified attribute. For a more complete example, see the let macro.

Aliases: @

Example: @[title]

Parameters

Parameter Description
0 The name of the attribute to retrieve.

attribute:

Sets the value of the specified attribute. For a more complete example, see the ‡‡‡‡‡PLACEHOLDER¤277‡‡‡‡‡ macro.

Aliases: @:

Example: @:[title|Test Title]

Parameters

Parameter Description
0 The name of the attribute to set.
1 The value of the attribute.

comment

Evaluates to nothing. Used to add comments in a Glyph document that will not be displayed in output files.

Aliases: --

Example: --[=>[#link|This link will not be evaluated]]

Parameters

Parameter Description
0 The contents to comment out

Remarks

Macros are not expanded within comments.

condition

Tests a conditional expression. For more information, see Conditional Macros.

Aliases: ?

Parameters

Parameter Description
0 The condition to test
1 The contents to expand if the condition is satisfied.

Remarks

For examples see any of the following:

config

Returns the value of a configuration setting.

Aliases: $

Example: $[document.author]

Parameters

Parameter Description
0 The full name of a configuration setting.

config:

Sets the value of a configuration setting.

Aliases: $:

Example: $:[document.draft|true]

Parameters

Parameter Description
0 The full name of a configuration setting.
1 The new value of the configuration setting

Remarks

This macro cannot be used in safe mode.

eq

Conditional equality operator, to be used with the condition macro.

Example: ?[eq[$[document.draft]|true]|This is displayed only in draft documents.]

Parameters

Parameter Description
0 The first expression to test
1 The second expression to test

escape

Evaluates to its value. Commonly used with the escaping delimiters [= and =].

Aliases: .

Example: .[=Macros are escaped here =>[#test].=]

Parameters

Parameter Description
0 The contents to escape.

fragment

Delimits a fragment of text that can be embedded using the embed macro.

Aliases: ##

Example: ##[test_fragment|This is an embeddable fragment]

Parameters

Parameter Description
0 The ID of the fragment.
1 The contents of the fragment.

embed

Embeds text previously-delimited using the fragment macro.

Aliases: &=

Example: &=[test_fragment]

Parameters

Parameter Description
0 The ID of the fragment.

gt

Returns true if the first parameter is gt the second one.

Example: greater than[5|2]

Parameters

Parameter Description
0 The first integer to compare.
1 The second integer to compare.

gte

Returns true if the first parameter is gte the second one.

Example: greater than or equal to[5|2]

Parameters

Parameter Description
0 The first integer to compare.
1 The second integer to compare.

include

Evaluates to the contents of a text file stored in the text/ directory referenced by its relative path. If the options.filters_by_file_extension setting is true, filters the contents of the file using the filter macro corresponding to the file extension.

Aliases: @

Example: include[frontmatter/introduction]

Parameters

Parameter Description
0 The file to include.

Remarks

  • This macro cannot be used in safe mode.

  • .glyph is assumed if no file extension is specified.
  • This macro can also be used to include .rb ruby files within the lib directory. File contents are evaluated in the context of the Glyph module.

let

Used to bind one or more attributes via the attribute macro. Actually, you can use attribute macro inside any other macro, but it looks tidier in this way.

Example

1let[
2  @:[a|2]
3  @:[b|3]
4  section[
5    @title[Testing]
6    @[title]: @[a] * @[b] = multiply[@[a]|@[b]] --[Outputs: Testing: 2 * 3 = 6]
7  ]
8]

Parameters

Parameter Description
0 Any content.

load

Embeds the contents of a file.

Example: load[my_samples.rb]

Parameters

Parameter Description
0 The file to embed, relative to the Glyph project folder.

lt

Returns true if the first parameter is lt the second one.

Example: less than[5|2]

Parameters

Parameter Description
0 The first integer to compare.
1 The second integer to compare.

lte

Returns true if the first parameter is lte the second one.

Example: less than or equal to[5|2]

Parameters

Parameter Description
0 The first integer to compare.
1 The second integer to compare.

match

Checks a string against a regular expression.

Example: ?[match[Hello!|/^hell/i]|This is always displayed]

Parameters

Parameter Description
0 The string to check.
1 The regular expression to match against the string.
2 The contents to expand if the string matches.

Remarks

This macro must be used with the condition macro.

macro:

Defines a macro.

Aliases: %:

Example: %:[test|"test: #{value}"]

Parameters

Parameter Description
0 The name of the new macro.
1 The macro definition (Ruby code).

Remarks

  • This macro cannot be used in safe mode.

  • The new macro can only be used after its declaration.

multiply

Multiplies two or more integers together.

Example: add[3|5|9]

not

Conditional not operator, to be used with the condition macro.

Example: ?[not[false]|This is always displayed.]

Parameters

Parameter Description
0 The expression to negate

output?

Evaluates to true if Glyph is generating output in the specified format(s).

Example: ?[output?[web|web5]|This text is printed only when generating web or web5 output.]

Parameters

Parameter Description
0, ... a valid output target.

or

Conditional or operator, to be used with the condition macro.

Example: ?[or[true|false]|This is always displayed.]

Parameters

Parameter Description
0 The first expression to test
1 The second expression to test

define:

Defines a new macro in Glyph code (for more information, see Defining macros using Glyph)

Aliases: def:

Example

 1def:[factorial|
 2  ?[
 3    eq[{{0}}|0]|1|
 4    multiply[
 5      {{0}} | factorial[subtract[{{0}}|1]]
 6    ]
 7  ]
 8]
 9factorial[5]

Parameters

Parameter Description
0 The name of the new macro.
0 The macro definition (Glyph code).

Remarks

  • The new macro can only be used after its declaration.
  • This macro cannot be used in safe mode.

ruby

Evaluates its value as Ruby code within the context of the Glyph module.

Aliases: % %[Time.now] %[Glyph::VERSION]

Parameters

Parameter Description
0 The Ruby code to evaluate.

Remarks

This macro cannot be used in safe mode.

s

Can be used to dispatch almost any instance method of the ruby String class.

s/match[This is a test string|/test/] s/sub[This is a test string|/a test/|another test]

snippet

Returns the value of a snippet.

Aliases: &

Example: &[glang]

Parameters

Parameter Description
0 The ID of the snippet to retrieve.

snippet:

Defines a snippet.

Aliases: &:

Example: &:[test|This is a test]

Parameters

Parameter Description
0 The ID of the new snippet.
1 The contents of the new snippet.

Remarks

The new snippet can only be used after its declaration.

subtract

Subtracts two or more integers together.

Example: add[10|5|2]

xml

When used composed with another macro, it can be used to render arbitrary raw XML tags.

Example: xml/img[@src[test.png]@alt[A Test image]]

while

Keeps evaluating the second parameter while a condition is satisfied.

Example

 1let[
 2  @count[5]
 3  @text[-]
 4  while[gt[@[count]|0]|
 5    @:[text|s/concat[@[text]|@[count]-]]          
 6    @:[count|subtract[@[count]|1]]
 7  ]
 8  @[text] --[Outputs: -5-4-3-2-1-]
 9]

Parameters

Parameter Description
0 The condition to check.
1 The code to evaluate while the condition is satisfied.