Skip to main content

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

Project description

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

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 :

---
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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pandoc-code-attribute, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size pandoc_code_attribute-0.1.4-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pandoc-code-attribute-0.1.4.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page