Skip to content

adoc admonitions.py

Georgios Pappas Jr edited this page Jan 3, 2022 · 2 revisions

Introduction

Pandoc filter that processes asciidoc-style admonitions and encloses them in a DIV with a specified class. These admonitions consist of a single line/paragraph message written in a simple manner and rendered according to a user configuration.

Syntax

The admonitions words appearing in the first column of a paragraph followed by a colon (:) and a space. For example:

NOTE: this is a note

These are invalid:

NOTE:this (no space after the colon)

NOTE: this (not in the first column)

Configuration

The default admonition names/classes are coded in the LINKS dictionary. The keys represent the admonition text (without the : ) and the value represents the class (HTML)/environment (LaTeX/beamer) that the paragraph will be enclosed into.

ADMONITIONS = { "NOTE": "note", "TIP": "tip", "ERROR": "error", "CODE": "term", "WARNING": "warn", "QUOTE": "quote" }

This can be overridden or expanded using a metadata block, at the top of your Markdown file, with the name adoc-admonition:

---
adoc-admonition:
    xxx: admonitionnote
    TIP: TIPADMONITION

...

With that in place, the changes will be:

xxx: xxx is a new admonition enclosed in a admonitionnote Div

TIP: overrides the default class and sets the new one as TIPADMONITION

In the specific case of Latex/Beamer output the admonitions are output inside an environment like:

NOTE: the note

\begin{note}
the note.
\end{note}

Installation

  1. Install python 3 (version >3.9) and pandoc

  2. Install panflute python libraries

    pip3 install panflute

  3. Download and place the file in directory:

    ~/.pandoc/filters

Usage in pandoc

pandoc -s test.md  -t beamer --filter adoc-admonitions.py

Author

Prof. Georgios Pappas Jr
University of Brasilia (UnB) - Brazil
Clone this wiki locally