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 and called by name.


## Installation

```shell
$ pip install foliantcontrib.macros
```


## Config

Enable the propressor by adding it to `preprocessors` and list your macros in `macros` dictionary:

```yaml
preprocessors:
- macros:
macros:
foo: This is a macro definition.
bar: "This is macro with a parameter: {0}"
```


## Usage

Here's the simplest usecase for macros:

```yaml
preprocessors:
- macros:
macros:
support_number: "8 800 123-45-67"
```

Now, everytime you need to insert your support phone number, you put a macro instead:

```markdown
Call you support team: <<macro name="support_number"></macro>.
```

Macros are 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:

```markdown
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:

```markdown
Here is [another page](#another_page).
```

This can be implemented using `<<if></if>` tag:

```markdown
Here is [another page](<if backends="pandoc">#another_page</if><if backends="mkdocs">another_page.md</if>).
```

This bulky constract quickly get old when you use many cross-references in you documentation.

To make your sources cleaner, move this construct to the config as a reusable macro:

```yaml
preprocessors:
- macros:
macros:
ref: <<if backends="pandoc">{0}</if><if backends="mkdocs">{1}</if>
```

And use it in the source:

```markdown
Here is [another page](<macro name="ref" params="#another_page, another_page.md"</macro>).
```

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.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

foliantcontrib.macros-1.0.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for foliantcontrib.macros-1.0.1.tar.gz
Algorithm Hash digest
SHA256 378eeeb2ce2c9c0f9f5de8099de7b6a0df579bd7027c1336759a6440985cc2db
MD5 a0bd1707666cf1e86bc20c1647087186
BLAKE2b-256 f7b0c47310ffde788a3613330ab9b25f115cf4b28aa9c200c80b5ad3971625f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for foliantcontrib.macros-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8b998f6bf4e1c21a13c73fb1c7715316356aa3b7a42996f438c6001848cad22
MD5 b6e2b2ad545832222afd751c0823b367
BLAKE2b-256 6ca9376077bad93fac3aad80525a61d0edd5eac3c229866c31859f3c828acfd0

See more details on using hashes here.

Supported by

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