Skip to main content

Macros for Foliant.

Project description

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 macros preprocessor must go before flags preprocessor in the config. This way macros will be already resolved at the time flags starts working.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

foliantcontrib.macros-1.0.5.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

foliantcontrib.macros-1.0.5-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file foliantcontrib.macros-1.0.5.tar.gz.

File metadata

  • Download URL: foliantcontrib.macros-1.0.5.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for foliantcontrib.macros-1.0.5.tar.gz
Algorithm Hash digest
SHA256 e6e85c0904e755a63e5955fc0bada14785e7679265d2bfdf173f31cb6de98004
MD5 6916d5de5298aa857d7687784b3e946c
BLAKE2b-256 e4f32458d28808abd8ba8bd8ccb268ff9549aa6a6fe803f17bbc219f720aa820

See more details on using hashes here.

File details

Details for the file foliantcontrib.macros-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for foliantcontrib.macros-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8dbbbe96bc97e28413f23848ff15f8f930c2688f5e5375b401cf8bb3521b7b49
MD5 690c0d70d74437daf20346dad1874d96
BLAKE2b-256 205c7adc0eb4f4125a0cfe45f3d0d775c29843027c3ffaf25baade8b18ea5acd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page