<commit_before>import datetime
import json
import re
import yaml

from django import template
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from markdown import markdown

from utilities.choices import unpack_grouped_choices
from utilities.utils import foreground_color


register = template.Library()


#
# Filters
#

@register.filter()
def oneline(value):
    """
    Replace each line break with a single space
    """
    value = value.replace('\r', '')
    return value.replace('\n', ' ')


@register.filter()
def placeholder(value):
    """
    Render a muted placeholder if value equates to False.
    """
    if value:
        return value
    placeholder = '<span class="text-muted">&mdash;</span>'
    return mark_safe(placeholder)


@register.filter()
def getlist(value, arg):
    """
    Return all values of a QueryDict key
    """
    return value.getlist(arg)


@register.filter
def getkey(value, key):
    """
    Return a dictionary item specified by key
    """
    return value[key]


@register.filter(is_safe=True)
def gfm(value):
    """
    Render text as GitHub-Flavored Markdown
    """
    # Strip HTML tags
    value = strip_tags(value)

    # Render Markdown with GFM extension
    html = markdown(value, extensions=['mdx_gfm'])

    return mark_safe(html)


@register.filter()
def render_json(value):
    """
    Render a dictionary as formatted JSON.
    """
    return json.dumps(value, indent=4, sort_keys=True)


@register.filter()
def render_yaml(value):
    """
    Render a dictionary as formatted YAML.
    """
    return yaml.dump(dict(value))


@register.filter()
def model_name(obj):
    """
    Return the name of the model of the given object
    """
    return obj._meta.verbose_name<commit_msg>Fixes #4150: Replace OrderedDict with Dict when rendering YAML<commit_after>import datetime
import json
import re
import yaml

from django import template
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from markdown import markdown

from utilities.choices import unpack_grouped_choices
from utilities.utils import foreground_color


register = template.Library()


#
# Filters
#

@register.filter()
def oneline(value):
    """
    Replace each line break with a single space
    """
    value = value.replace('\r', '')
    return value.replace('\n', ' ')


@register.filter()
def placeholder(value):
    """
    Render a muted placeholder if value equates to False.
    """
    if value:
        return value
    placeholder = '<span class="text-muted">&mdash;</span>'
    return mark_safe(placeholder)


@register.filter()
def getlist(value, arg):
    """
    Return all values of a QueryDict key
    """
    return value.getlist(arg)


@register.filter
def getkey(value, key):
    """
    Return a dictionary item specified by key
    """
    return value[key]


@register.filter(is_safe=True)
def gfm(value):
    """
    Render text as GitHub-Flavored Markdown
    """
    # Strip HTML tags
    value = strip_tags(value)

    # Render Markdown with GFM extension
    html = markdown(value, extensions=['mdx_gfm'])

    return mark_safe(html)


@register.filter()
def render_json(value):
    """
    Render a dictionary as formatted JSON.
    """
    return json.dumps(value, indent=4, sort_keys=True)


@register.filter()
def render_yaml(value):
    """
    Render a dictionary as formatted YAML.
    """
    return yaml.dump(json.loads(json.dumps(value)))


@register.filter()
def model_name(obj):
    """
    Return the name of the model of the given object
    """
    return obj._meta.verbose_name
{'fraction_non_alphanumeric': 0.10991438829052748, 'fraction_numerical': 0.0016570008285004142, 'mean_word_length': 3.4224664224664223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1355228', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1078, 'n_words': 325}