Macros for Foliant
Macro is a string with placeholders that is replaced with predefined content during documentation build. Macros are defined in the config.
Installation
$ pip install foliantcontrib.macros
Config
Enable the preprocessor by adding it to preprocessors and listing your macros in macros dictionary:
preprocessors:
- macros:
macros:
foo: This is a macro definition.
bar: "This is macro with a parameter: {param}"
Usage
Here's the simplest usecase for macros:
preprocessors:
- macros:
macros:
support_number: "8 800 123-45-67"
Now, every time you need to insert your support phone number, you put a macro instead:
Call you support team: <macro>support_number</macro>.
Here's the number again: <m>support_number</m>.
Macros support params. This simple feature may make your sources a lot tidier:
preprocessors:
- macros:
macros:
jira: "https://mycompany.jira.server.us/jira/ticket?ID={ticket_id}"
Now you don't need to remember the address of your Jira server if you want to reference a ticket:
Link to jira ticket: <macro ticket_id="DOC-123">jira</macro>
Realworld example
You can combine Macros with tags by other Foliant preprocessors.
This can useful in documentation that should be built into multiple targets, e.g. site and pdf, when the same thing is done differently in one target than in the other.
For example, to reference a page in MkDocs, you just put the Markdown file in the link:
Here is [another page](another_page.md).
But when building documents with Pandoc all sources are flattened into a single Markdown, so you refer to different parts of the document by anchor links:
Here is [another page](#another_page).
This can be implemented using the Flags preprocessor and its <if></if> tag:
Here is [another page](<if backends="pandoc">#another_page</if><if backends="mkdocs">another_page.md</if>).
This bulky construct quickly gets old when you use many cross-references in your documentation.
To make your sources cleaner, move this construct to the config as a reusable macro:
preprocessors:
- macros:
macros:
ref: <if backends="pandoc">{pandoc}</if><if backends="mkdocs">{mkdocs}</if>
- flags
And use it in the source:
Here is [another page](<macro pandoc="#another_page" mkdocs="another_page.md">ref</macro>).
Just remember, that in this use case
macrospreprocessor must go beforeflagspreprocessor in the config. This way macros will be already resolved at the timeflagsstarts working.
Metadata
Release files for foliantcontrib.macros 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| foliantcontrib.macros-1.0.5.tar.gz | 3.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| foliantcontrib.macros-1.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / foliantcontrib.macros-1.0.5.tar.gz
| Download URL | foliantcontrib.macros-1.0.5.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6e85c0904e755a63e5955fc0bada14785e7679265d2bfdf173f31cb6de98004
|
|
BLAKE2b-256 checksum How to use checksums |
e4f32458d28808abd8ba8bd8ccb268ff9549aa6a6fe803f17bbc219f720aa820
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / foliantcontrib.macros-1.0.5-py3-none-any.whl
| Download URL | foliantcontrib.macros-1.0.5-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8dbbbe96bc97e28413f23848ff15f8f930c2688f5e5375b401cf8bb3521b7b49
|
|
BLAKE2b-256 checksum How to use checksums |
205c7adc0eb4f4125a0cfe45f3d0d775c29843027c3ffaf25baade8b18ea5acd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for foliantcontrib.macros 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.