<commit_before>#!/usr/bin/env python

# Author: <NAME> <<EMAIL>>
# Copyright: (c) 2016 <NAME>
# License: MIT


"""
Pandoc filter to replace certain LaTeX macros with matching HTML tags.

In my beamer slides I use certain macros like `\blueArrow` which produces an
arrow in deep blue color. This filter translates this TeX macros into the
corresponding HTML markup.

Note, that the `html.css` must also be included in the template for proper
rendering.

This filter will also remove HTML comments (like `<!-- ... -->`) from the AST.
"""

from pandocfilters import toJSONFilter, attributes, Span, Str, Space, RawInline, Image
import re

trans = [{'class': 'blueArrow', 're': re.compile('\\\\blueArrow'), 'cont': "=>", 'key': 'Str'},
         {'class': 'alert', 're': re.compile('\\\\alert\{(.*)\}$'), 'cont': 1, 'key': 'Grp'},
         {'class': 'Alert', 're': re.compile('\\\\Alert\{(.*)\}$'), 'cont': 1, 'key': 'Grp'},
         {'class': 'code', 're': re.compile('\\\\code\{(.*)\}$'), 'cont': 1, 'key': 'Grp'},
         {'class': 'bsp', 're': re.compile('\\\\bsp\{(.*)\}$'), 'cont': 1, 'key': 'Grp'}]
cboxStart = re.compile('\\\\cboxbegin')
cboxEnd   = re.compile('\\\\cboxend')
comment   = re.compile('<!--(.*)-->', re.MULTILINE | re.DOTALL)

def textohtml(key, value, format, meta):
    if key == 'RawInline':
        fmt, s = value
        if fmt == "tex":
            for x in trans:
                m = x['re'].match(s)
                if m:
                    return [Span(attributes({'class': x['class']}),
                                 [Str( x['cont'] if x['key']=='Str' else m.group(x['cont']) )]),
                            Space()]
            if cboxStart.match(s):
                return RawInline("html", "<span class='cbox'>")
            if cboxEnd.match(s):
                return RawInline("html", "</span>")
    if key == 'RawBlock':
        fmt, s = value
        if fmt == "html":
            if comment.match(s):
                return []
<commit_msg>clean-up: Pandoc 2.1.x remove HTML comments automatically -- no need for a filter anymore ...<commit_after>#!/usr/bin/env python

# Author: <NAME> <<EMAIL>>
# Copyright: (c) 2016 <NAME>
# License: MIT


"""
Pandoc filter to replace certain LaTeX macros with matching HTML tags.

In my beamer slides I use certain macros like `\blueArrow` which produces an
arrow in deep blue color. This filter translates this TeX macros into the
corresponding HTML markup.

Note, that the `html.css` must also be included in the template for proper
rendering.
"""

from pandocfilters import toJSONFilter, attributes, Span, Str, Space, RawInline, Image
import re

trans = [{'class': 'blueArrow', 're': re.compile('\\\\blueArrow'), 'cont': "=>", 'key': 'Str'},
         {'class': 'alert', 're': re.compile('\\\\alert\{(.*)\}$'), 'cont': 1, 'key': 'Grp'},
         {'class': 'Alert', 're': re.compile('\\\\Alert\{(.*)\}$'), 'cont': 1, 'key': 'Grp'},
         {'class': 'code', 're': re.compile('\\\\code\{(.*)\}$'), 'cont': 1, 'key': 'Grp'},
         {'class': 'bsp', 're': re.compile('\\\\bsp\{(.*)\}$'), 'cont': 1, 'key': 'Grp'}]
cboxStart = re.compile('\\\\cboxbegin')
cboxEnd   = re.compile('\\\\cboxend')

def textohtml(key, value, format, meta):
    if key == 'RawInline':
        fmt, s = value
        if fmt == "tex":
            for x in trans:
                m = x['re'].match(s)
                if m:
                    return [Span(attributes({'class': x['class']}),
                                 [Str( x['cont'] if x['key']=='Str' else m.group(x['cont']) )]),
                            Space()]
            if cboxStart.match(s):
                return RawInline("html", "<span class='cbox'>")
            if cboxEnd.match(s):
                return RawInline("html", "</span>")

{'fraction_non_alphanumeric': 0.2103723404255319, 'fraction_numerical': 0.0047872340425531915, 'mean_word_length': 2.4222020018198362, 'pattern_counts': {'":': 3, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3771893', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1176, 'n_words': 368}