aboutsummaryrefslogtreecommitdiff
path: root/tools/pandocfilter-pygments.py
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-02-15 23:28:50 +0000
committerJuan J. Martinez <jjm@usebox.net>2022-02-15 23:28:50 +0000
commit31418a90da67a1bcd1af0a39f33e8ecc5cdd2d49 (patch)
tree1127a547c91af3cb71912c6572a44c76484a1982 /tools/pandocfilter-pygments.py
parent9c984aa67d2bd607032ba7fa911c77f9bbf87d4c (diff)
downloadubox-msx-lib-31418a90da67a1bcd1af0a39f33e8ecc5cdd2d49.tar.gz
ubox-msx-lib-31418a90da67a1bcd1af0a39f33e8ecc5cdd2d49.zip
Use black for formatting
Diffstat (limited to 'tools/pandocfilter-pygments.py')
-rwxr-xr-xtools/pandocfilter-pygments.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/tools/pandocfilter-pygments.py b/tools/pandocfilter-pygments.py
index ee678f8..2b4161f 100755
--- a/tools/pandocfilter-pygments.py
+++ b/tools/pandocfilter-pygments.py
@@ -10,28 +10,29 @@ Requires:
from pandocfilters import toJSONFilter, RawBlock
from pygments import highlight
-from pygments.lexers import (get_lexer_by_name, guess_lexer, TextLexer)
+from pygments.lexers import get_lexer_by_name, guess_lexer, TextLexer
from pygments.formatters import get_formatter_by_name
+
def pygmentize(key, value, format, meta):
- if key == 'CodeBlock':
- [[ident, classes, keyvals], code] = value
- lexer = None
- for klass in classes:
- try:
- lexer = get_lexer_by_name(klass)
- break
- except:
- pass
- if lexer is None:
- try:
- lexer = guess_lexer(code)
- except:
- lexer = TextLexer()
- if format == "html5":
- format = "html"
- return [RawBlock(format, highlight(code, lexer, get_formatter_by_name(format)))]
+ if key == "CodeBlock":
+ [[ident, classes, keyvals], code] = value
+ lexer = None
+ for klass in classes:
+ try:
+ lexer = get_lexer_by_name(klass)
+ break
+ except:
+ pass
+ if lexer is None:
+ try:
+ lexer = guess_lexer(code)
+ except:
+ lexer = TextLexer()
+ if format == "html5":
+ format = "html"
+ return [RawBlock(format, highlight(code, lexer, get_formatter_by_name(format)))]
+
if __name__ == "__main__":
toJSONFilter(pygmentize)
-