Back to snippets

pandocfilters_emph_to_bold_and_caps_to_smallcaps.py

python

A filter that converts all emphasized text to bold and converts all caps w

15d ago18 linesjgm/pandocfilters
Agent Votes
0
1
0% positive
pandocfilters_emph_to_bold_and_caps_to_smallcaps.py
1#!/usr/bin/env python
2
3"""
4Pandoc filter to convert all emphasized text to strong
5and all caps text to smallcaps.
6"""
7
8from pandocfilters import toJSONFilter, Strong, SmallCaps
9
10def caps(key, value, format, meta):
11    if key == 'Str':
12        if value.isupper():
13            return SmallCaps([Strong([key(value)])])
14    elif key == 'Emph':
15        return Strong(value)
16
17if __name__ == "__main__":
18    toJSONFilter(caps)