Skip to main content

pandoc-code-attribute

Pandoc filter to add attributes to code blocks based on their classes.

Installation

First install python and python-pip.

Then use pip to install:

pip3 install --user pandoc-code-attribute

Usage

Configuration

By default, this filter won’t add style attributes to prevent undefined errors.

You can enable it by setting code-attribute field in metadata.

To add attributes to all classes, use:

code-attribute: true

To add attributes to specific classes, use:

code-attribute:
    - cpp

Example

This pandoc filter will add attributes to code blocks based on their classes.

For example, it can be very useful to use different styles for different language in listings :

---
code-attribute:
    - cpp
    - python
header-includes: |
    \usepackage{listings}
    \usepackage[usenames,dvipsnames]{color}

    \lstset{ % General settings
        numbers=left,
        numberstyle=\tiny
    }

    \lstdefinestyle{cpp}{ % Only for C++
        keywordstyle=\color{Green}
    }

    \lstdefinestyle{python}{ % Only for Python
        keywordstyle=\color{Magenta}
    }
---

C++:

```cpp
int main(int argc, char *argv[])
{
    return 0;
}
```

Python:

```python
def main():
    print('Hello')

if __name__ == '__main__':
    main()
```

Then compile the example (--listings is needed only for this example):

pandoc input.md --filter pandoc-code-attribute --listings -o output.pdf

Results:

Command

In general, to use this filter, just add this filter to pandoc command:

pandoc input.md --filter pandoc-code-attribute -o output.pdf

License

MIT License

Metadata

Release files for pandoc-code-attribute 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pandoc-code-attribute 0.2.0
File Size Uploaded Provenance
pandoc-code-attribute-0.2.0.tar.gz 2.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pandoc-code-attribute 0.2.0
File Interpreter ABI Platform
pandoc_code_attribute-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.2 kB

Release files / pandoc-code-attribute-0.2.0.tar.gz

Download URL pandoc-code-attribute-0.2.0.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6841b57ca8e0ff39d9840008b80c7d6f68aab7af3be934d49a76f2c8cbf44dfa
BLAKE2b-256 checksum
How to use checksums
4d84b8a9dc7189671d014c746fcf5dd88c3a76df2f7c792de0ad4b15f92b82fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Release files / pandoc_code_attribute-0.2.0-py3-none-any.whl

Download URL pandoc_code_attribute-0.2.0-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dff229e5fa78213b3de7dfa6a2c5f72a89ef3fbc9b3163593a58f926834befb8
BLAKE2b-256 checksum
How to use checksums
637dfafaba845f2bbf3aeb3f4ec54a1f8be9c8454ccf1db7fdc66a8fc34b1153
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Security for pandoc-code-attribute 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page