<commit_before># coding: utf-8
"""
    kurrent.writers.html
    ~~~~~~~~~~~~~~~~~~~~

    :copyright: 2013 by <NAME>
    :license: BSD, see LICENSE.rst for details
"""
from contextlib import contextmanager

from markupsafe import escape

from .base import Writer


class HTML5Writer(Writer):
    def write_Text(self, node):
        self.write(escape(node.text))

    @contextmanager
    def write_Paragraph(self, node):
        self.write(u'<p>')
        yield True
        self.write(u'</p>')

    def write_Header(self, node):
        self.write(u'<h%d>' % node.level)
        self.write(escape(node.text))
        self.write(u'</h%d>' % node.level)

    @contextmanager
    def write_UnorderedList(self, node):
        self.write(u'<ul>')
        yield True
        self.write(u'</ul>')

    @contextmanager
    def write_ListItem(self, node):
        self.write(u'<li>')
        yield True
        self.write(u'</li>')

    @contextmanager
    def write_Document(self, node):
        self.write(u'<!doctype html>')
        self.write(u'<title>%s</title>' % (
            escape(node.metadata.get('title', u''))
        ))
        yield True

    @contextmanager
    def write_Emphasis(self, node):
        self.write(u'<em>')
        yield True
        self.write(u'</em>')

    @contextmanager
    def write_Strong(self, node):
        self.write(u'<strong>')
        yield True
        self.write(u'</strong>')

    def write_Reference(self, node):
        self.write(u'<a href="')
        self.write(node.definition)
        self.write(u'">')
        self.write(escape(node.text))
        self.write(u'</a>')

    def write_Definition(self, node):
        # prevents NotImplementedError, we ignore Definitions
        pass

    @contextmanager
    def write_BlockQuote(self, node):
        self.write(u'<blockquote>')
        yield True
        self.write(u'</blockquote>')<commit_msg>Refactor HTML5Writer<commit_after># coding: utf-8
"""
    kurrent.writers.html
    ~~~~~~~~~~~~~~~~~~~~

    :copyright: 2013 by <NAME>
    :license: BSD, see LICENSE.rst for details
"""
from contextlib import contextmanager

from markupsafe import escape

from .base import Writer


def make_block_writer(tag):
    @contextmanager
    def write(self, node):
        self.write(u'<%s>' % tag)
        yield True
        self.write(u'</%s>' % tag)
    return write


class HTML5Writer(Writer):
    def write_Text(self, node):
        self.write(escape(node.text))

    write_Paragraph = make_block_writer(u'p')
    write_ListItem = make_block_writer(u'li')
    write_OrderedList = make_block_writer(u'ol')
    write_UnorderedList = make_block_writer(u'ul')
    write_Emphasis = make_block_writer(u'em')
    write_Strong = make_block_writer(u'strong')
    write_BlockQuote = make_block_writer(u'blockquote')

    def write_Header(self, node):
        self.write(u'<h%d>' % node.level)
        self.write(escape(node.text))
        self.write(u'</h%d>' % node.level)

    @contextmanager
    def write_Document(self, node):
        self.write(u'<!doctype html>')
        self.write(u'<title>%s</title>' % (
            escape(node.metadata.get('title', u''))
        ))
        yield True

    def write_Reference(self, node):
        self.write(u'<a href="')
        self.write(node.definition)
        self.write(u'">')
        self.write(escape(node.text))
        self.write(u'</a>')

    def write_Definition(self, node):
        # prevents NotImplementedError, we ignore Definitions
        pass
{'fraction_non_alphanumeric': 0.1484240687679083, 'fraction_numerical': 0.0037249283667621777, 'mean_word_length': 2.7020148462354188, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '3913764', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1116, 'n_words': 214}