Configuration
Most configuration for hexdoc can be done in the hexdoc.toml
(or doc/hexdoc.toml
) file.
File paths
Most file paths in the hexdoc.toml
file are resolved relative to the location of the config file, not the working directory of the hexdoc
command or the root of the Git repository.
For example, in the below file structure, the following hexdoc.toml
file would correctly reference the src/main/resources
directory, regardless of where the hexdoc
command is executed from:
.
├── doc/
│ └── hexdoc.toml
└── src/
└── main/
└── resources/
resource_dirs = [
"../src/main/resources",
]
TOML placeholders
The hexdoc.toml
parser includes a custom placeholder interpolation system, similar to JSONPath, that allows referencing other values in the config file (eg. for reusing common values).
Placeholders are added to strings in the format {key}
, similar to Python's f-strings. The string may also contain other text outside of the placeholder. By default, placeholder keys are resolved relative to the table containing the placeholder.
- Before parsing
- After parsing
key = "foo {var} baz"
var = "bar"
key = "foo bar baz"
var = "bar"
Placeholders must reference keys containing string values; the following example is invalid and would raise an error.
- Before parsing
- After parsing
key = "{var}"
var = 0
key = <INVALID>
var = 0
Parent references
The key ^
may be used to reference the table containing the current table (ie. the parent table). It can be used multiple times to reference grandparents, great-grandparents, and so on. Parent references may optionally be separated and/or followed by .
characters.
- Before parsing
- After parsing
[foo]
key1 = "{^baz.var}"
[foo.bar]
key2 = "{^^baz.var}"
key3 = "{^.^.baz.var}"
[baz]
var = "value"
[foo]
key1 = "value"
[foo.bar]
key2 = "value"
key3 = "value"
[baz]
var = "value"
Root references
The key $
may be used at the start of a placeholder key to reference the root table of the TOML file. It may optionally be followed by a .
character.
- Before parsing
- After parsing
[foo]
key1 = "{$baz.var}"
[foo.bar]
key2 = "$.baz.var"
[baz]
var = "value"
[foo]
key1 = "value"
[foo.bar]
key2 = "value"
[baz]
var = "value"
Arrays
Placeholders in arrays are resolved relative to the table containing the array. However, placeholders in tables within arrays are resolved relative to the table in the array.
- Before parsing
- After parsing
key1 = [
"{var}",
{ key2="{^var}" }
]
var = "value"
key1 = [
"value",
{ key2="value" }
]
var = "value"
For this reason, it is usually more readable to use root references within arrays.
- Before parsing
- After parsing
key1 = [
"{$var}",
{ key2="{$var}" }
]
var = "value"
key1 = [
"value",
{ key2="value" }
]
var = "value"
Custom fields
To make your hexdoc.toml
file easier to maintain, you can add custom fields starting with the prefix _
. All fields starting with _
will be silently ignored by hexdoc (instead of raising a validation error for unrecognized fields).
For example, custom fields and placeholders are used by the hexdoc project templates to define common paths that are used in multiple places:
- Before parsing
- After parsing
resource_dirs = [
"{$_common.src}/main/resources",
{ path="{$_common.src}/generated/resources", required=false },
]
[[extra.hexcasting.pattern_stubs]]
path = "{$_common.package}/Patterns.java"
[_common]
src = "../common/src"
package = "{src}/main/java/com/example"
resource_dirs = [
"../common/src/main/resources",
{ path="../common/src/generated/resources", required=false },
]
[[extra.hexcasting.pattern_stubs]]
path = "../common/src/main/java/com/example/Patterns.java"
Note that since the _common
table starts with _
, the fields within that table (eg. _common.src
) are not parsed by hexdoc, so they don't need to start with _
.
This is similar to Docker Compose's Extensions feature.
Intrinsic functions
Intrinsic functions are tables with a key starting with the prefix !
that are handled specially by the TOML parser.
To use an intrinsic function, create a table with a single entry, where the key is the name of the function, and the value is the input to the function. For example:
- Before parsing
- After parsing
key1 = "value" # normal value
key2."!Raw" = "value" # !Raw function (option 1)
key3 = { "!Raw"="value" } # !Raw function (option 2)
key1 = "value" # normal value
key2 = "value" # !Raw function (option 1)
key3 = "value" # !Raw function (option 2)
The last two examples above are logically equivalent in TOML, and are both equivalent to the following JSON value before being parsed by hexdoc.
{
"key": {
"!Raw": "value"
}
}
!Raw
Outputs the value passed to this function as-is, without any further processing (eg. string placeholders and intrinsic functions will not be expanded). Useful for defining regular expressions.
- Before parsing
- After parsing
pattern1."!Raw" = "^{.+}$"
pattern2 = { "!Raw"="^{.+}$" }
pattern1 = "^{.+}$"
pattern2 = "^{.+}$"
!None
Outputs None
. The input value is ignored. This function is necessary because TOML does not have a null
keyword.
- Before parsing
- After parsing
null1."!None" = ""
null2 = { "!None"="" }
null1 = None
null2 = None
JSON Schema
If you use a TOML validator with JSON Schema support (eg. the Even Better TOML VSCode extension), you can get autocomplete and validation for hexdoc.toml
files by using the autogenerated JSON Schema definition.
With Taplo-based tools like Even Better TOML, you can enable the schema by adding the following comment to the top of hexdoc.toml
(docs):
#:schema https://hexdoc.hexxy.media/schema/core/Properties.json