MyNixOS website logo
Description

Pandoc filter to customize links, images and paragraphs.

Pandoc filter to customize links, images and paragraphs (with restrictions). Styles are read from the metadata of the document: they may reside inside the document or in a separate YAML file.

styleFromMeta

Hackage

Pandoc filter to apply styles found in the metadata of the document to various objects.

Styling is supported for following types of objects:

  • Standalone and inlined images
  • Links
  • Paragraphs (with restrictions, see below)

Styles are read from the metadata of the document: they may reside inside the document or in a separate YAML file. For example1,

    ---
    img_style :
      html : |
        ~~~~~
        <div style="clear: both; text-align: center; margin-bottom: 16px">
        <a href="$SRC$" style="margin-left: 10em;" alt="$ALT$">
        <img border="0" src="$SRC$" /></a></div>
        ~~~~~
      latex : |
        ~~~~~
        \begin{center}
        \includegraphics{$$SRC$$}
        \end{center}
        ~~~~~
      rst: |
        ~~~~~
        .. image:: $$SRC$$
           :height: 100px
           :width: 200 px
           :scale: 50 %
           :alt: $$ALT$$
           :align: right
        ~~~~~
      haddock: |
        ~~~~~
        <<$$SRC$$ An image $ALT$>>
        ~~~~~
    link_style :
      html : |
        ~~~~~
        <a href="$SRC$" style="margin-left: 1em; margin-right: 1em;">$ALT$</a>
        ~~~~~
      latex : |
        ~~~~~
        \href{$SRC$}{\colorbox{green}{$ALT$}}
        ~~~~~
    para_style :
      html : |
        <span style="display: block; margin-bottom: 16px;"></span>
    ...

declares styles img_style, link_style and para_style. Their names (except for the last) are arbitrarily chosen and may be referred from the document, for example

    ![$img_style$](../images/an_image.png)
    [$link_style$ *here*](http://example.com/)

Placeholders $ALT$, $SRC$ and $TITLE$ from style declarations are to be replaced by corresponding data found in the object declaration. In this example *here* corresponds to $ALT$, and http://example.com/ corresponds to $SRC$. Placeholders $$SRC$$ and $$TITLE$$ are replaced verbatim, in $$ALT$$ all formatting gets removed. In the example $$SRC$$ is used to keep underscores unescaped as they may reside in image names.

Notice that all metablocks contents, with the exclusion of para_style, are wrapped inside code blocks. This let the contents be substituted verbatim for any output format. However, raw HTML and TeX blocks are well supported by Pandoc, so we could rewrite parts of the example like this:

    ---
    img_style :
      html : |
        <div style="clear: both; text-align: center; margin-bottom: 16px">
        <a href="$SRC$" style="margin-left: 10em;" alt="$ALT$">
        <img border="0" src="$SRC$" /></a></div>
      latex : |
        \begin{center}
        \includegraphics{$$SRC$$}
        \end{center}

    # ...

    ...

The filter has support for raw HTML and TeX blocks, but this support is not complete, and in some cases substitutions may fail. In addition, Pandoc may re-format substitutions. That's why this method is not recommended to use.

As soon as paragraphs do not have place where to put extra data, style para_style is applied to all paragraphs in the document. Currently, only transformation to a span block is supported (which is probably useful only in HTML). Any contents found between opening and closing span tags are ignored: actual paragraph contents will be inserted inside them. Notice that wrapping inside code blocks is not allowed in para_style block.

Build and install the filter with commands

$ cabal build
$ cabal install

The program is also available at Hackage, so you can install it with

$ cabal install pandoc-stylefrommeta



1  All YAML and markdown code examples in this document have 4-space indentation as the document requires this for correct rendering. As such, when they are copied and pasted for playing around, the indentation must be removed!

Metadata

Version

0.4.0.0

Executables (1)

  • bin/styleFromMeta

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows