<commit_before>import hashlib
import hoedown
from os import path
from urllib import parse

import jinja2
import jinja2.ext
import jinja2.runtime
import markupsafe

import vj4
import vj4.constant
import vj4.job
from vj4.util import json
from vj4.util import options


class Undefined(jinja2.runtime.Undefined):
  def __getitem__(self, _):
    return self

  if options.debug:
    __str__ = jinja2.runtime.Undefined.__call__


class Environment(jinja2.Environment):
  def __init__(self):
    super(Environment, self).__init__(
        loader=jinja2.FileSystemLoader(path.join(path.dirname(__file__), 'ui/templates')),
        extensions=[jinja2.ext.with_],
        auto_reload=options.debug,
        autoescape=True,
        trim_blocks=True,
        undefined=Undefined)
    globals()[self.__class__.__name__] = lambda: self  # singleton

    self.globals['vj4'] = vj4
    self.globals['static_url'] = lambda s: options.cdn_prefix + s
    self.globals['paginate'] = paginate

    self.filters['markdown'] = markdown
    self.filters['json'] = json.encode
    self.filters['gravatar_url'] = gravatar_url


MARKDOWN_EXTENSIONS = (hoedown.EXT_TABLES |  # Parse PHP-Markdown style tables.
                       hoedown.EXT_FENCED_CODE |  # Parse fenced code blocks.
                       hoedown.EXT_AUTOLINK |  # Automatically turn safe URLs into links.
                       hoedown.EXT_NO_INTRA_EMPHASIS |  # Disable emphasis_between_words.
                       hoedown.EXT_MATH |  # Parse TeX $$math$$ syntax, Kramdown style.
                       hoedown.EXT_MATH_EXPLICIT )  # Instead of guessing by context, parse $inline math$ and $$always block math$$ (requires EXT_MATH).
MARKDOWN_RENDER_FLAGS = (hoedown.HTML_ESCAPE |  # Escape all HTML.
                         hoedown.HTML_HARD_WRAP)  # Render each linebreak as <br>.


def markdown(text):
  return markupsafe.Markup(
      hoedown.html(text, extensions=MARKDOWN_EXTENSIONS, render_flags=MARKDOWN_RENDER_FLAGS))


def gravatar_url(gravatar, size=200):
  # TODO: 'd' should be https://domain/img/avatar.png
  if gravatar:<commit_msg>ui revision<commit_after>import hashlib
import hoedown
from os import path
from urllib import parse

import jinja2
import jinja2.ext
import jinja2.runtime
import markupsafe

import vj4
import vj4.constant
import vj4.job
from vj4.util import json
from vj4.util import options
from vj4.util import version


class Undefined(jinja2.runtime.Undefined):
  def __getitem__(self, _):
    return self

  if options.debug:
    __str__ = jinja2.runtime.Undefined.__call__


class Environment(jinja2.Environment):
  def __init__(self):
    super(Environment, self).__init__(
        loader=jinja2.FileSystemLoader(path.join(path.dirname(__file__), 'ui/templates')),
        extensions=[jinja2.ext.with_],
        auto_reload=options.debug,
        autoescape=True,
        trim_blocks=True,
        undefined=Undefined)
    globals()[self.__class__.__name__] = lambda: self  # singleton

    self.globals['vj4'] = vj4
    self.globals['static_url'] = lambda s: options.cdn_prefix + s + '?{0}'.format(version.get())
    self.globals['paginate'] = paginate

    self.filters['markdown'] = markdown
    self.filters['json'] = json.encode
    self.filters['gravatar_url'] = gravatar_url


MARKDOWN_EXTENSIONS = (hoedown.EXT_TABLES |  # Parse PHP-Markdown style tables.
                       hoedown.EXT_FENCED_CODE |  # Parse fenced code blocks.
                       hoedown.EXT_AUTOLINK |  # Automatically turn safe URLs into links.
                       hoedown.EXT_NO_INTRA_EMPHASIS |  # Disable emphasis_between_words.
                       hoedown.EXT_MATH |  # Parse TeX $$math$$ syntax, Kramdown style.
                       hoedown.EXT_MATH_EXPLICIT )  # Instead of guessing by context, parse $inline math$ and $$always block math$$ (requires EXT_MATH).
MARKDOWN_RENDER_FLAGS = (hoedown.HTML_ESCAPE |  # Escape all HTML.
                         hoedown.HTML_HARD_WRAP)  # Render each linebreak as <br>.


def markdown(text):
  return markupsafe.Markup(
      hoedown.html(text, extensions=MARKDOWN_EXTENSIONS, render_flags=MARKDOWN_RENDER_FLAGS))


def gravatar_url(gravatar, size=200):
  # TODO: 'd' should be https://domain/img/avatar.png
  if gravatar:
{'fraction_non_alphanumeric': 0.09571966133584196, 'fraction_numerical': 0.008936970837253057, 'mean_word_length': 3.2067260138476756, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '457502', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1367, 'n_words': 299}