# Path: coaster/utils/text.py
# LINKIFY_CALLBACKS = list(DEFAULT_CALLBACKS) + [dont_linkify_filenames]
# 
# LINKIFY_SKIP_TAGS: List = ['pre', 'code', 'kbd', 'samp', 'var']
# 
# VALID_TAGS: Mapping[str, List[str]] = {
#     'a': ['href', 'title', 'target', 'rel'],
#     'abbr': ['title'],
#     'b': [],
#     'br': [],
#     'blockquote': [],
#     'cite': [],
#     'code': [],
#     'dd': [],
#     'del': [],
#     'dl': [],
#     'dt': [],
#     'em': [],
#     'h3': [],
#     'h4': [],
#     'h5': [],
#     'h6': [],
#     'hr': [],
#     'i': [],
#     'img': ['src', 'width', 'height', 'align', 'alt'],
#     'ins': [],
#     'li': [],
#     'mark': [],
#     'p': [],
#     'pre': [],
#     'ol': ['start'],
#     'strong': [],
#     'sup': [],
#     'sub': [],
#     'ul': [],
# }
# 
# def normalize_spaces_multiline(text):
#     """
#     Replace whitespace characters with regular spaces, in multiline text.
# 
#     Line break characters like newlines are not considered whitespace.
#     """
#     return re_multiline_spaces.sub(' ', text)
# 
# def sanitize_html(value, valid_tags=None, strip=True, linkify=False):
#     """Strip unwanted markup out of HTML."""
#     if valid_tags is None:
#         valid_tags = VALID_TAGS
#     if linkify:
#         filters = [
#             partial(
#                 LinkifyFilter, callbacks=LINKIFY_CALLBACKS, skip_tags=LINKIFY_SKIP_TAGS
#             )
#         ]
#     else:
#         filters = []
#     cleaner = Cleaner(
#         tags=list(valid_tags.keys()),
#         attributes=valid_tags,
#         filters=filters,
#         strip=strip,
#     )
#     return Markup(cleaner.clean(value))


from copy import deepcopy
from typing import Any, Dict, List, Mapping, Optional, Union, cast, overload
from bleach import linkify as linkify_processor
from markdown import Markdown
from markdown.extensions import Extension
from markdown.treeprocessors import Treeprocessor
from markupsafe import Markup
from pymdownx.emoji import to_alt as emoji_to_alt
from .text import (
    LINKIFY_CALLBACKS,
    LINKIFY_SKIP_TAGS,
    VALID_TAGS,
    normalize_spaces_multiline,
    sanitize_html,
)
"""
Markdown processor
==================

Markdown parser with a number of sane defaults that resembles
GitHub-Flavoured Markdown (GFM).

GFM exists because normal markdown has some vicious gotchas. Further reading:
http://blog.stackoverflow.com/2009/10/markdown-one-year-later/

This Markdown processor is used by :func:`~coaster.sqlalchemy.columns.MarkdownColumn`
to auto-render HTML from Markdown text.
"""




__all__ = [
    'markdown',
    'MARKDOWN_HTML_TAGS',
    'default_markdown_extensions_html',
    'default_markdown_extensions',
    'default_markdown_extension_configs',
]


# --- Constants ------------------------------------------------------------------------


# Path: coaster/utils/text.py
# LINKIFY_CALLBACKS = list(DEFAULT_CALLBACKS) + [dont_linkify_filenames]
# 
# LINKIFY_SKIP_TAGS: List = ['pre', 'code', 'kbd', 'samp', 'var']
# 
# VALID_TAGS: Mapping[str, List[str]] = {
#     'a': ['href', 'title', 'target', 'rel'],
#     'abbr': ['title'],
#     'b': [],
#     'br': [],
#     'blockquote': [],
#     'cite': [],
#     'code': [],
#     'dd': [],
#     'del': [],
#     'dl': [],
#     'dt': [],
#     'em': [],
#     'h3': [],
#     'h4': [],
#     'h5': [],
#     'h6': [],
#     'hr': [],
#     'i': [],
#     'img': ['src', 'width', 'height', 'align', 'alt'],
#     'ins': [],
#     'li': [],
#     'mark': [],
#     'p': [],
#     'pre': [],
#     'ol': ['start'],
#     'strong': [],
#     'sup': [],
#     'sub': [],
#     'ul': [],
# }
# 
# def normalize_spaces_multiline(text):
#     """
#     Replace whitespace characters with regular spaces, in multiline text.
# 
#     Line break characters like newlines are not considered whitespace.
#     """
#     return re_multiline_spaces.sub(' ', text)
# 
# def sanitize_html(value, valid_tags=None, strip=True, linkify=False):
#     """Strip unwanted markup out of HTML."""
#     if valid_tags is None:
#         valid_tags = VALID_TAGS
#     if linkify:
#         filters = [
#             partial(
#                 LinkifyFilter, callbacks=LINKIFY_CALLBACKS, skip_tags=LINKIFY_SKIP_TAGS
#             )
#         ]
#     else:
#         filters = []
#     cleaner = Cleaner(
#         tags=list(valid_tags.keys()),
#         attributes=valid_tags,
#         filters=filters,
#         strip=strip,
#     )
#     return Markup(cleaner.clean(value))


# Path: coaster/utils/markdown.py
from copy import deepcopy
from typing import Any, Dict, List, Mapping, Optional, Union, cast, overload
from bleach import linkify as linkify_processor
from markdown import Markdown
from markdown.extensions import Extension
from markdown.treeprocessors import Treeprocessor
from markupsafe import Markup
from pymdownx.emoji import to_alt as emoji_to_alt
from .text import (
    LINKIFY_CALLBACKS,
    LINKIFY_SKIP_TAGS,
    VALID_TAGS,
    normalize_spaces_multiline,
    sanitize_html,
)

"""
Markdown processor
==================

Markdown parser with a number of sane defaults that resembles
GitHub-Flavoured Markdown (GFM).

GFM exists because normal markdown has some vicious gotchas. Further reading:
http://blog.stackoverflow.com/2009/10/markdown-one-year-later/

This Markdown processor is used by :func:`~coaster.sqlalchemy.columns.MarkdownColumn`
to auto-render HTML from Markdown text.
"""




__all__ = [
    'markdown',
    'MARKDOWN_HTML_TAGS',
    'default_markdown_extensions_html',
    'default_markdown_extensions',
    'default_markdown_extension_configs',
]


# --- Constants ------------------------------------------------------------------------


MARKDOWN_HTML_TAGS = deepcopy(VALID_TAGS)