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

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.0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

foliantcontrib.macros-1.0.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

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