# Path: readme_renderer/clean.py
# def clean(html, tags=None, attributes=None, styles=None):
#     if tags is None:
#         tags = ALLOWED_TAGS
#     if attributes is None:
#         attributes = ALLOWED_ATTRIBUTES
#     if styles is None:
#         styles = ALLOWED_STYLES
# 
#     # Clean the output using Bleach
#     cleaner = bleach.sanitizer.Cleaner(
#         tags=tags,
#         attributes=attributes,
#         styles=styles,
#         filters=[
#             # Bleach Linkify makes it easy to modify links, however, we will
#             # not be using it to create additional links.
#             functools.partial(
#                 bleach.linkifier.LinkifyFilter,
#                 callbacks=[
#                     lambda attrs, new: attrs if not new else None,
#                     bleach.callbacks.nofollow,
#                 ],
#                 skip_tags=["pre"],
#                 parse_email=False,
#             ),
#             DisabledCheckboxInputsFilter,
#         ],
#     )
#     try:
#         cleaned = cleaner.clean(html)
#         return cleaned
#     except ValueError:
#         return None


import io
from docutils.core import publish_parts
from docutils.writers.html4css1 import HTMLTranslator, Writer
from docutils.utils import SystemMessage
from .clean import clean
    # Use the short form of syntax highlighting so that the generated
    # Pygments CSS can be used to style the output.
    "syntax_highlight": "short",

    # Maximum width (in characters) for one-column field names.
    # 0 means "no limit"
    "field_name_limit": 0,
}


def render(raw, stream=None, **kwargs):
    if stream is None:
        # Use a io.StringIO as the warning stream to prevent warnings from
        # being printed to sys.stderr.
        stream = io.StringIO()

    settings = SETTINGS.copy()
    settings["warning_stream"] = stream

    writer = Writer()
    writer.translator_class = ReadMeHTMLTranslator

    try:
        parts = publish_parts(raw, writer=writer, settings_overrides=settings)
    except SystemMessage:
        rendered = None
    else:
        rendered = parts.get("docinfo", "") + parts.get("fragment", "")

    if rendered:

# Path: readme_renderer/clean.py
# def clean(html, tags=None, attributes=None, styles=None):
#     if tags is None:
#         tags = ALLOWED_TAGS
#     if attributes is None:
#         attributes = ALLOWED_ATTRIBUTES
#     if styles is None:
#         styles = ALLOWED_STYLES
# 
#     # Clean the output using Bleach
#     cleaner = bleach.sanitizer.Cleaner(
#         tags=tags,
#         attributes=attributes,
#         styles=styles,
#         filters=[
#             # Bleach Linkify makes it easy to modify links, however, we will
#             # not be using it to create additional links.
#             functools.partial(
#                 bleach.linkifier.LinkifyFilter,
#                 callbacks=[
#                     lambda attrs, new: attrs if not new else None,
#                     bleach.callbacks.nofollow,
#                 ],
#                 skip_tags=["pre"],
#                 parse_email=False,
#             ),
#             DisabledCheckboxInputsFilter,
#         ],
#     )
#     try:
#         cleaned = cleaner.clean(html)
#         return cleaned
#     except ValueError:
#         return None


# Path: readme_renderer/rst.py
import io
from docutils.core import publish_parts
from docutils.writers.html4css1 import HTMLTranslator, Writer
from docutils.utils import SystemMessage
from .clean import clean

    # Use the short form of syntax highlighting so that the generated
    # Pygments CSS can be used to style the output.
    "syntax_highlight": "short",

    # Maximum width (in characters) for one-column field names.
    # 0 means "no limit"
    "field_name_limit": 0,
}


def render(raw, stream=None, **kwargs):
    if stream is None:
        # Use a io.StringIO as the warning stream to prevent warnings from
        # being printed to sys.stderr.
        stream = io.StringIO()

    settings = SETTINGS.copy()
    settings["warning_stream"] = stream

    writer = Writer()
    writer.translator_class = ReadMeHTMLTranslator

    try:
        parts = publish_parts(raw, writer=writer, settings_overrides=settings)
    except SystemMessage:
        rendered = None
    else:
        rendered = parts.get("docinfo", "") + parts.get("fragment", "")

    if rendered:

        return clean(rendered)