# BSD 2-Clause License
#
# Apprise - Push Notification Library.
# Copyright (c) 2026, Chris Caron And a paragraph too. Some obnoxious text here. line 1 line 2 line 3 line 1 line 2 line 3 line 1> line 2 line 3>")
== "line 1\nline 2\nline 3>"
)
# Make sure we ignore fields that aren't important to us
assert (
to_html(
""
" line 1
")
assert "Lots and lots" in clist
assert "of lists." in clist
assert "To be or not to be." in to_html(
"To be or not to be.
"
)
cspace = to_html(
"Fancy heading
Plus line break.
and )
assert (
to_html("some information
and more information")
== "some information\n\nand more information"
)
#
# Test bad tags
#
# first 2 entries are okay, but last will do as best as it can
assert (
to_html("
3rd line" ) == "line 1 bold\nmy link\n3rd line" ) #
FROM: apprise-test@mydomain.yyy
FROM: apprise-test@mydomain.yyy
line 1
line 2
line 3
") == "line 1\n\nline 2\n\nline 3" ) # Case sensitivity -- tag names are case-insensitive in HTML assert ( to_md("line 1
line 2
line 3
") == "line 1\n\nline 2\n\nline 3" ) # HTMLParser lowercases ALL tag names -- inline tags included assert to_md("bold text") == "**bold text**" assert to_md("italic") == "*italic*" # Uppercase self-closingline 1>" "
line 2" "
line 3>"
) == (
"# Heading 1\n## Heading 2\n### Heading 3\n"
"#### Heading 4\n##### Heading 5\n###### Heading 6\n\n"
"line 1\n\n*line 2*\n\nline 3\\>"
)
# and both produce bold markers
assert to_md("bold text") == "**bold text**"
assert to_md("bold text") == "**bold text**"
# and both produce italic markers
assert to_md("italic") == "*italic*"
assert to_md("italic") == "*italic*"
# Angle destinations prevent parentheses in an href from ending links.
assert (
to_md(
" 3rd line"
)
== "line 1 **bold**\n\n[my link]()\n\n3rd line"
)
# produces Markdown link syntax
assert (
to_md("test my link")
== "test [my link](<#>)"
)
# with nested inline markup -- the href must survive the child tags
assert to_md("hello world") == (
"[**hello** world]()"
)
assert to_md("label") == (
"[**label**]()"
)
assert (
to_md("italic and plain")
== "[*italic* and plain]()"
)
# Nested -- inner href wins for its own span; outer wraps the rest
assert (
to_md("text link")
== "[text [link]()]()"
)
# with no href attribute -- content rendered as plain text
assert to_md("test no link") == "test no link"
# Bare anchor (no href) -- text passes through unchanged
assert to_md("jump target") == "jump target"
# is inline -- it passes text through without a newline; Some obnoxious text here. line 1 price: 5 * 3 Tag #1 Use `func` And a paragraph too. first child
assert to_md(" alpha first child.
assert (
to_md(" alpha beta children inside one one two for second.
assert (
to_md(" wrapped children
assert (
to_md(" first second sibling inside the same more keep keep keep Click [here](https://evil.example.com) now An image  too back\\*slash _literal_ my_variable_name ~strikethrough~ previously <script>alert(1)</script> 1. Apples 2. Oranges 23. done - not a bullet, just a dash + plus sign list? Some text --- more text Some text --- more text ___ - - - Hello world Heading well-known v1.2 it is not - really price is $5.00 a-b-c 5 - 3 = 2 ab , so every line of real content is followed by a
# blank (but still "> "-prefixed) separator line.
one_per_level = " x x wraps in backticks without a block boundary
assert to_md("func()") == "`func()`"
# Markdown special characters inside are NOT escaped -- backtick
# delimiters already make content literal
assert to_md("x*2 and #tag") == "`x*2 and #tag`"
# produces a fenced code block
assert to_md("text") == "text"
assert to_md("text") == "text"
# Markdown/HTML injection via plain text content
assert (
to_md("line a\nline b
") == "```\nline a\nline b\n```"
# is treated the same as (fenced block)
assert to_md("output\nhere") == "```\noutput\nhere\n```"
# Inline code followed immediately by a pre block
assert to_md(
"multi-line 1\nmulti-line 2more content"
"multi-line 1\nmulti-line 2
more content"
) == (
"`multi-line 1\nmulti-line 2`more content"
"\n```\nmulti-line 1\nmulti-line 2\n```\nmore content"
)
# Unordered lists produce "- " prefixed items
result = to_md("
")
assert "- Lots and lots" in result
assert "- of lists." in result
assert (
to_md("To be or not to be.
")
== "> To be or not to be."
)
# Standalone
produces just "---"
assert to_md("
") == "---"
assert to_md("
") == "---"
# "
"
"""
)
== "Let's handle special html encoding\n\n---"
)
# Missing is handled gracefully
assert (
to_md(
"Heading
Plus line break.
")
== "- alpha\n- beta\n- gamma"
)
# Flat ordered list with auto-incrementing counter
assert (
to_md("
")
== "1. first\n2. second\n3. third"
)
# shifts where the auto-incrementing counter begins
assert to_md('
') == "4. a\n5. b"
assert to_md('
') == "0. a"
# CommonMark list markers cannot represent negative starting values.
assert to_md('
') == "0. a\n1. b"
# A non-numeric start is ignored, same as no attribute at all
assert to_md('
') == "1. a"
#
') == "5. a\n6. b"
assert (
to_md('
')
== "1. a\n10. b\n11. c"
)
assert to_md('
') == "0. a\n1. b"
# A non-numeric value is ignored too -- the counter just keeps incrementing
# normally, same as if the attribute weren't there
assert to_md('
') == "1. a\n2. b"
# Nested unordered lists (2 levels)
assert (
to_md(
"
"
)
== "- top A\n - nested A\n- top B"
)
# Nested unordered lists (3 levels)
assert (
to_md("
")
== "- L1\n - L2\n - L3"
)
# Mixed nesting: ol inside ul
assert (
to_md(
""
"
"
)
== "- intro\n 1. step one\n 2. step two"
)
# Mixed nesting: ul inside ol
assert (
to_md(
""
"
"
"
"
)
== "1. first\n - sub A\n - sub B\n2. second"
)
# Malformed HTML: missing "
"
HTMLParser does not synthesize
# implicit close events; each missing is simply absent, but the next.
assert (
to_md("
assert to_md("
")
== "- item A\n- item B\n- item C"
)
# Without , ordered-list counters cannot advance.
assert (
to_md("
") == "1. one\n1. two\n1. three"
)
# Malformed HTML: missing closing
assert to_md(" (no
is in
# IGNORE_TAGS so unwrapped text is suppressed entirely
assert to_md("
bare text
") == ""
# inside
")
== "- run `cmd --flag` now"
)
# Markdown special characters inside cmd --flag now are NOT escaped
assert (
to_md("text") == "text"
assert to_md("
")
== "- see `x*2 #tag`"
)
# Fenced blocks retain content and list indentation.
assert (
to_md("x*2 #tag
")
== "- code:\n ```\n indented\n here\n ```"
)
# Nested fenced blocks combine content indentation with list indentation.
assert (
to_md(
" indented\n here
"
)
== "- outer\n - inner:\n ```\n x = 1\n ```"
)
# A first-child block shares the list marker's line.
# Single item with a x = 1
") == "- alpha"
# Multiple items each with a
")
== "- alpha\n\n- beta"
)
# Multiple
") == "- one\n\n two"
# Mixed: direct text for first item,
")
== "- direct\n- wrapped"
)
# Numbered list with
")
== "1. first\n\n2. second"
)
# link as first child of
")
== "- [link]()\n\n more"
)
def test_conversion_html_to_markdown_escaping():
"""Test Markdown escaping."""
def to_md(body):
"""Wrapper to simplify html-to-markdown conversion tests."""
return convert_between(NotifyFormat.HTML, NotifyFormat.MARKDOWN, body)
# Embedded backticks widen code delimiters.
assert to_md("a`b") == "``a`b``"
# Content starting or ending with a backtick gets a padding space, per
# CommonMark's code-span disambiguation rule
assert to_md("`x") == "`` `x ``"
assert to_md("x`") == "`` x` ``"
# A run of 3 backticks inside widens the fence past 3
assert to_md("boom```
") == "````\nboom```\n````"
# Plain content with no backticks still uses the minimal delimiter
assert to_md("x
") == "```\nx\n```"
# Ignored containers suppress both text and Markdown markers.
assert (
to_md(
"ignorehidden heading
text")
== "text"
)
# A list marker ("- ") must not leak from a
text")
== "text"
)
# block fully inside a suppressed container emits nothing, not even
# an empty fence
assert to_md("before link after
")
== "```\nbefore link after\n```"
)
assert (
to_md("before bold after") == "`before bold after`"
)
# Stray code/pre/samp close tags
assert to_md("
***") == "\\*\\*\\*"
assert to_md("
===
---
") == "- A\n- B"
# A stray close tag with content on BOTH sides must be a complete no-op,
# not just absorbed because nothing preceded it.
assert to_md("ab") == "ab"
assert to_md("ab") == "ab"
assert to_md("ab") == "ab"
assert to_md("ab") == "ab"
assert to_md("ab") == "ab"
assert to_md("ab") == "ab"
# A stray / close still falls through cleanly when content follows.
assert to_md(" " * 50
+ "
" * 50
+ "text"
)
== "text"
)
# deep nesting still resolve correctly.
assert (
to_md("
" * 50 + "
" * 50) == "- visible"
)
# List indentation is capped at LIST_DEPTH_MAX ---
assert LIST_DEPTH_MAX == 4
one_per_level = "
" * 10
out = to_md(one_per_level)
lines = out.split("\n")
assert len(lines) == 10
# Indent grows for the first LIST_DEPTH_MAX levels...
assert lines[0] == "- x"
assert lines[1] == " - x"
assert lines[2] == " - x"
assert lines[3] == " - x"
# ...then holds steady for every level beyond the cap
for line in lines[4:]:
assert line == " - x"
# Performance: same shape, large enough that the old O(N^2)
n = 20000
deep = "
" * n
start = default_timer()
out = to_md(deep)
elapsed = default_timer() - start
assert len(out) < 20 * n
# Generous bound: this must catch a real return to quadratic
# behavior, not just run fast on a quiet dev machine -- shared or
# emulated build infrastructure (e.g. a busy Koji builder) can be
# many times slower.
assert elapsed < 15.0
# Performance: many UNCLOSED tags followed by many closing tags of
# a *different* kind that's never actually open ("").
n = 20000
html = "
" * n + "" * n
start = default_timer()
out = to_md(html)
elapsed = default_timer() - start
assert len(out) < 20 * n
# Generous bound: this must catch a real return to quadratic
# behavior, not just run fast on a quiet dev machine -- shared or
# emulated build infrastructure (e.g. a busy Koji builder) can be
# many times slower.
assert elapsed < 15.0
# Blockquote depth is capped at BLOCKQUOTE_DEPTH_MAX
assert BLOCKQUOTE_DEPTH_MAX == 4
# Each level is its own
" * 10
out = to_md(one_per_level)
lines = out.split("\n")
assert len(lines) == 19
content_lines = lines[0::2]
separator_lines = lines[1::2]
assert len(content_lines) == 10
assert content_lines[0] == "> x"
assert content_lines[1] == "> > x"
assert content_lines[2] == "> > > x"
assert content_lines[3] == "> > > > x"
for line in content_lines[4:]:
assert line == "> > > > x"
# Each separator matches its preceding content line, minus the "x"
for content, separator in zip(content_lines, separator_lines):
assert separator == content[: -len("x")].rstrip()
n = 20000
deep = "
" * n
start = default_timer()
out = to_md(deep)
elapsed = default_timer() - start
assert len(out) < 20 * n
# Generous bound: this must catch a real return to quadratic
# behavior, not just run fast on a quiet dev machine -- shared or
# emulated build infrastructure (e.g. a busy Koji builder) can be
# many times slower.
assert elapsed < 15.0
# When emphasis or anchor tags are nested past MAX_FRAME_DEPTH, _push_frame
# returns False and the opening delimiter must NOT be emitted.
depth = MAX_FRAME_DEPTH + 1
em_open = "" * depth
em_close = "" * depth
out_em = to_md(f"{em_open}text{em_close}")
# The text must appear; no unmatched bare asterisk may leak through.
assert "text" in out_em
assert out_em.replace("*", "").strip() == "text"
# Same guard for -- no unmatched "[" in the output.
a_open = '' * depth
a_close = "" * depth
out_a = to_md(f"{a_open}text{a_close}")
assert "text" in out_a
# Count "[" and "](" -- every "[" must have a matching "](".
assert out_a.count("[") == out_a.count("](")
# At MAX_FRAME_DEPTH the frame is discarded and _push_frame
# returns False.
bq_open = "
" * depth
bq_close = "
" * depth
out_bq = to_md(f"{bq_open}text{bq_close}")
assert "text" in out_bq
# Every ">" line-prefix must correspond to a real nested blockquote level.
first_line = out_bq.splitlines()[0] if out_bq else ""
gt_count = len(first_line) - len(first_line.lstrip("> "))
assert gt_count <= BLOCKQUOTE_DEPTH_MAX * 2 # ">" + " " per level
# At MAX_FRAME_DEPTH the " + "
"
out_li = to_md(f"{li_open}text{li_close}")
assert "text" in out_li
def test_conversion_headings_to_bold():
"""Convert supported ATX headings for chat dialects without headings."""
# Convert the common heading forms generated from HTML.
assert commonmark_headings_to_bold("# Alert") == "**Alert**"
assert commonmark_headings_to_bold("###### Alert") == "**Alert**"
# An optional closing sequence of "#" is stripped, not kept as text.
assert commonmark_headings_to_bold("## foo ##") == "**foo**"
assert commonmark_headings_to_bold("# foo #####") == "**foo**"
# A hash without preceding whitespace remains part of the heading text.
assert commonmark_headings_to_bold("# foo#") == "**foo#**"
# Preserve up to three spaces allowed before a heading.
assert commonmark_headings_to_bold(" # one space") == " **one space**"
assert commonmark_headings_to_bold(" # three spaces") == (
" **three spaces**"
)
# Four leading spaces make an indented code block, not a heading.
four_spaces = " # four spaces"
assert commonmark_headings_to_bold(four_spaces) == four_spaces
# Empty headings do not produce empty bold markers.
assert commonmark_headings_to_bold("###") == ""
assert commonmark_headings_to_bold("### ") == ""
# Heading text requires whitespace after its opening hashes.
literal = "#nospace"
assert commonmark_headings_to_bold(literal) == literal
# Inline code spans are never touched.
assert commonmark_headings_to_bold("`# inline code`") == (
"`# inline code`"
)
# Backtick and tilde fences protect heading-like code.
fenced_backtick = "```\n# not a heading\n```"
assert commonmark_headings_to_bold(fenced_backtick) == fenced_backtick
fenced_tilde = "~~~\n# not a heading either\n~~~"
assert commonmark_headings_to_bold(fenced_tilde) == fenced_tilde
# An unfinished fence protects the remaining text.
unterminated = "```\n# still not a heading\nmore text"
assert commonmark_headings_to_bold(unterminated) == unterminated
# A real heading before and after a fenced block is still converted.
mixed = "# Before\n```\n# inside\n```\n# After"
assert commonmark_headings_to_bold(mixed) == (
"**Before**\n```\n# inside\n```\n**After**"
)
# Preserve blockquote markers emitted by HTML-to-CommonMark conversion.
assert commonmark_headings_to_bold("> # Alert") == "> **Alert**"
assert commonmark_headings_to_bold("> > # Alert") == "> > **Alert**"
assert commonmark_headings_to_bold("> > > # Alert") == ("> > > **Alert**")
# Preserve unordered and ordered list markers.
assert commonmark_headings_to_bold("- # Alert") == "- **Alert**"
assert commonmark_headings_to_bold("* # Alert") == "* **Alert**"
assert commonmark_headings_to_bold("+ # Alert") == "+ **Alert**"
assert commonmark_headings_to_bold("1. # Alert") == "1. **Alert**"
assert commonmark_headings_to_bold("2) # Alert") == "2) **Alert**"
# Preserve combined blockquote and list markers.
assert commonmark_headings_to_bold("> - # Alert") == "> - **Alert**"
# Keep the blockquote marker for an empty heading.
assert commonmark_headings_to_bold("> ###") == "> "
# Recognize CRLF fences without protecting later headings.
crlf_fence = "```\r\ncode\r\n```\r\n# Real Heading"
assert commonmark_headings_to_bold(crlf_fence) == (
"```\r\ncode\r\n```\r\n**Real Heading**"
)
# Invalid backtick fence labels do not protect later headings.
invalid_opener = (
"Some `inline` text\n"
"```code`with`backtick info string\n"
"more text\n"
"# Real Heading"
)
assert commonmark_headings_to_bold(invalid_opener) == (
"Some `inline` text\n"
"```code`with`backtick info string\n"
"more text\n"
"**Real Heading**"
)
# Tilde fence labels may contain backticks.
tilde_with_backtick = "~~~code`ok\nreal code\n~~~"
assert (
commonmark_headings_to_bold(tilde_with_backtick) == tilde_with_backtick
)
# Preserve heading-like text inside a quoted tilde fence.
quoted_tilde_fence = "> ~~~\n> # literal code\n> ~~~"
assert (
commonmark_headings_to_bold(quoted_tilde_fence) == quoted_tilde_fence
)
# Repeating ``"- "`` starts a sibling list item, so these are three
# separate items. The middle heading remains real Markdown and converts.
three_sibling_items = "- ~~~\n- # literal code\n- ~~~~"
assert commonmark_headings_to_bold(three_sibling_items) == (
"- ~~~\n- **literal code**\n- ~~~~"
)
# A backtick closer wider than its opener still closes the fence, even
# when both are nested inside a blockquote.
quoted_wider_closer = "> ```\n> # literal code\n> ````"
assert (
commonmark_headings_to_bold(quoted_wider_closer) == quoted_wider_closer
)
# Nested blockquotes around a fence are recognized at every level.
nested_quoted_fence = "> > ~~~\n> > # literal code\n> > ~~~"
assert (
commonmark_headings_to_bold(nested_quoted_fence) == nested_quoted_fence
)
# Quote markers may have up to three leading spaces.
assert commonmark_headings_to_bold(" > # Alert") == " > **Alert**"
indented_quoted_fence = " > ~~~\n > # literal code\n > ~~~"
assert (
commonmark_headings_to_bold(indented_quoted_fence)
== indented_quoted_fence
)
# Four leading spaces create indented code, not a top-level fence.
# The following real heading must therefore still be converted.
four_space_fence_then_heading = (
" ~~~\n not a real fence\n ~~~\n# Real Heading"
)
assert commonmark_headings_to_bold(four_space_fence_then_heading) == (
" ~~~\n not a real fence\n ~~~\n**Real Heading**"
)
# An ordered-list marker can be wider than three characters ("123. "
# is five), so its continuation lines need more than three leading
# spaces too. A real heading after the fence must still convert.
wide_ordered_fence = "123. ~~~\n # literal\n ~~~\n\n# real"
assert commonmark_headings_to_bold(wide_ordered_fence) == (
"123. ~~~\n # literal\n ~~~\n\n**real**"
)
# A list containing a quote puts the list marker first, while continuation
# lines replace it with spaces. Both prefix orders belong to one container.
list_then_quote_fence = "- > ~~~\n > # literal\n > ~~~\n\n# real"
assert commonmark_headings_to_bold(list_then_quote_fence) == (
"- > ~~~\n > # literal\n > ~~~\n\n**real**"
)
# Up to three leading spaces may belong to a top-level fence rather than
# a list. Its heading-like content must remain protected.
lightly_indented_fence = " ~~~\n# literal\n ~~~\n# real"
assert commonmark_headings_to_bold(lightly_indented_fence) == (
" ~~~\n# literal\n ~~~\n**real**"
)
# Opening and closing fences have independent indentation allowances.
mismatched_indent_fence = "~~~\n# literal\n ~~~\n# real"
assert commonmark_headings_to_bold(mismatched_indent_fence) == (
"~~~\n# literal\n ~~~\n**real**"
)
# The same closer slack applies inside a blockquote.
quoted_mismatched_indent_fence = "> ~~~\n> # literal\n> ~~~\n> # real"
assert commonmark_headings_to_bold(quoted_mismatched_indent_fence) == (
"> ~~~\n> # literal\n> ~~~\n> **real**"
)
# A lightly indented fence can continue a list item without repeating
# its marker. An unfinished fence stops when that list item ends.
unclosed_narrow_list_fence = "- intro\n ~~~\n # literal\n\n# real"
assert commonmark_headings_to_bold(unclosed_narrow_list_fence) == (
"- intro\n ~~~\n # literal\n\n**real**"
)
# A later top-level fence cannot close the list's unfinished fence.
unclosed_narrow_list_fence_with_later_fence = (
"- intro\n ~~~\n # literal\n\n# real\n\n~~~\nunrelated\n~~~"
)
assert commonmark_headings_to_bold(
unclosed_narrow_list_fence_with_later_fence
) == ("- intro\n ~~~\n # literal\n\n**real**\n\n~~~\nunrelated\n~~~")
# Blank lines before the fence may remain within the list item.
unclosed_narrow_list_fence_with_blank = (
"- intro\n\n ~~~\n # literal\n\n# real"
)
assert commonmark_headings_to_bold(
unclosed_narrow_list_fence_with_blank
) == ("- intro\n\n ~~~\n # literal\n\n**real**")
# Light indentation without an earlier list marker is top-level.
unmarked_indent_no_list_behind_it = (
"Some intro text\n ~~~\n# literal\n ~~~\n# real"
)
assert commonmark_headings_to_bold(unmarked_indent_no_list_behind_it) == (
"Some intro text\n ~~~\n# literal\n ~~~\n**real**"
)
# The paragraph lazily continues the list, but one-space fence indentation
# is still insufficient for the two-space item.
list_ended_by_unindented_paragraph = (
"- intro\nunindented paragraph\n ~~~\n# literal\n ~~~\n# real"
)
assert commonmark_headings_to_bold(list_ended_by_unindented_paragraph) == (
"- intro\nunindented paragraph\n ~~~\n# literal\n ~~~\n**real**"
)
# Indented list text may appear between the marker and fence.
unclosed_narrow_list_fence_with_paragraph = (
"- intro\n more text in the same item\n ~~~\n # literal\n\n# real"
)
assert commonmark_headings_to_bold(
unclosed_narrow_list_fence_with_paragraph
) == (
"- intro\n more text in the same item\n ~~~\n # literal\n\n**real**"
)
# The HTML converter replaces a list marker with equal-width spaces on
# continuation lines. Test that real output as well as synthetic input.
list_only_fence_html = (
"
"
"# literal\nmoreReal Heading
"
)
list_only_fence_body = html_to_markdown(list_only_fence_html)
assert list_only_fence_body == (
"- ```\n # literal\n more\n ```\n\n# Real Heading"
)
converted = commonmark_headings_to_bold(list_only_fence_body)
# The heading-like line inside the fence stays literal code.
assert " # literal\n" in converted
# A real heading placed after the fenced block still converts.
assert converted.endswith("\n**Real Heading**")
# Also cover a preceding paragraph and the wider numbered-list marker.
text_then_fence_html = (
"
"
"# literal\nmoreReal Heading
"
)
text_then_fence_body = html_to_markdown(text_then_fence_html)
assert text_then_fence_body == (
"- intro\n ```\n # literal\n more\n ```\n\n# Real Heading"
)
converted = commonmark_headings_to_bold(text_then_fence_body)
assert " # literal\n" in converted
assert converted.endswith("\n**Real Heading**")
ordered_fence_html = (
"
"
"# literal\nmoreReal Heading
"
)
ordered_fence_body = html_to_markdown(ordered_fence_html)
assert ordered_fence_body == (
"1. ```\n # literal\n more\n ```\n\n# Real Heading"
)
converted = commonmark_headings_to_bold(ordered_fence_body)
assert " # literal\n" in converted
assert converted.endswith("\n**Real Heading**")
# List continuation spacing moves before the quote marker on later lines.
quoted_list_fence_html = (
"
"
"# literal\nmoreReal Heading
"
)
quoted_list_fence_body = html_to_markdown(quoted_list_fence_html)
assert quoted_list_fence_body == (
"> - intro\n > ```\n > # literal\n > more\n > ```"
"\n\n# Real Heading"
)
converted = commonmark_headings_to_bold(quoted_list_fence_body)
assert " > # literal\n" in converted
assert converted.endswith("\n**Real Heading**")
# Leading list indentation contributes to the continuation width, whether
# the fence begins the item or follows its introductory text.
indented_marker_then_fence = " - ~~~\n # literal\n ~~~\n# real"
assert commonmark_headings_to_bold(indented_marker_then_fence) == (
" - ~~~\n # literal\n ~~~\n**real**"
)
indented_marker_with_intro = " - intro\n ~~~\n # literal\n\n# real"
assert commonmark_headings_to_bold(indented_marker_with_intro) == (
" - intro\n ~~~\n # literal\n\n**real**"
)
# A literal "- " inside a closed fence must not create list state for the
# unfinished top-level fence that follows it.
marker_like_text_inside_closed_fence = (
"~~~\n- literal\n ~~~\n ~~~\n# still code"
)
assert commonmark_headings_to_bold(
marker_like_text_inside_closed_fence
) == ("~~~\n- literal\n ~~~\n ~~~\n# still code")
# Ending an inner list restores the still-open outer list width.
nested_list_falls_back_to_outer = (
"- outer\n - inner\n text\n ~~~\n # literal\n\n# real"
)
assert commonmark_headings_to_bold(nested_list_falls_back_to_outer) == (
"- outer\n - inner\n text\n ~~~\n # literal\n\n**real**"
)
# An unindented paragraph may lazily continue an open list item.
lazy_continuation_keeps_list_open = (
"- intro\nlazy continuation\n ~~~\n # literal\n\n# real"
)
assert commonmark_headings_to_bold(lazy_continuation_keeps_list_open) == (
"- intro\nlazy continuation\n ~~~\n # literal\n\n**real**"
)
# A new list marker ends lazy paragraph continuation.
new_marker_ends_lazy_continuation = (
"- intro\nordinary text\n- newitem\n ~~~\n # literal\n\n# real"
)
assert commonmark_headings_to_bold(new_marker_ends_lazy_continuation) == (
"- intro\nordinary text\n- newitem\n ~~~\n # literal\n\n**real**"
)
# A list fence closer may add only three columns of indentation.
# Greater indentation leaves it open until the list ends.
wildly_overindented_list_closer = (
"- intro\n ```\n code\n ```\n# real"
)
assert commonmark_headings_to_bold(wildly_overindented_list_closer) == (
"- intro\n ```\n code\n ```\n**real**"
)
# The same three-column closer limit applies outside lists.
wildly_overindented_top_level_closer = "```\ncode\n ```\n# after"
assert commonmark_headings_to_bold(
wildly_overindented_top_level_closer
) == ("```\ncode\n ```\n# after")
# ``-\t`` reaches column four. Two spaces cannot continue that list, so
# the following unfinished fence is top-level and protects the remainder.
tab_expanded_marker_width = "-\tintro\n ```\n # literal\n\n# real"
assert commonmark_headings_to_bold(tab_expanded_marker_width) == (
tab_expanded_marker_width
)
# A tab reaches the same column as ``-\t``, keeping the fence in the list.
tab_expanded_continuation_width = "-\tintro\n\t```\n\t# literal\n\n# real"
assert commonmark_headings_to_bold(tab_expanded_continuation_width) == (
"-\tintro\n\t```\n\t# literal\n\n**real**"
)
# Accept quote-first continuation lines as well as Apprise's list-first
# output when a fenced block is nested in both containers.
quote_then_list_continuation = "- > ~~~\n> # literal\n> ~~~\n\n# real"
assert commonmark_headings_to_bold(quote_then_list_continuation) == (
"- > ~~~\n> # literal\n> ~~~\n\n**real**"
)
# A quote-first closer still needs the list's full indentation.
quote_then_list_insufficient_width = (
"- > ~~~\n> # literal\n> ~~~\n> ~~~\n\n# real"
)
assert commonmark_headings_to_bold(quote_then_list_insufficient_width) == (
"- > ~~~\n> # literal\n> ~~~\n> ~~~\n\n**real**"
)
# List indentation without the required quote marker ends the container.
list_width_met_but_no_quote_at_all = (
"- > ~~~\n text without quote\n> ~~~\n\n# real"
)
assert commonmark_headings_to_bold(list_width_met_but_no_quote_at_all) == (
"- > ~~~\n text without quote\n> ~~~\n\n**real**"
)
# A bare quote marker still satisfies its quote depth.
bare_quote_marker_line_in_combo = "- > ~~~\n>\n> ~~~\n\n# real"
assert commonmark_headings_to_bold(bare_quote_marker_line_in_combo) == (
"- > ~~~\n>\n> ~~~\n\n**real**"
)
# A heading ends the list, making the following unfinished fence top-level.
heading_ends_list_before_fence = (
"- intro\n# outside\n ~~~\n # literal\n# still code"
)
assert commonmark_headings_to_bold(heading_ends_list_before_fence) == (
"- intro\n**outside**\n ~~~\n # literal\n# still code"
)
# A heading inside a list marker cannot gain a lazy continuation.
marker_content_is_heading = (
"- # heading\noutside\n ~~~\n # literal\n# still code"
)
assert commonmark_headings_to_bold(marker_content_is_heading) == (
"- **heading**\noutside\n ~~~\n # literal\n# still code"
)
# Blockquotes and thematic breaks also end lazy list continuation.
blockquote_ends_list_before_fence = (
"- intro\n> outside\n ~~~\n # literal\n# still code"
)
assert commonmark_headings_to_bold(blockquote_ends_list_before_fence) == (
"- intro\n> outside\n ~~~\n # literal\n# still code"
)
thematic_break_ends_list_before_fence = (
"- intro\n---\n ~~~\n # literal\n# still code"
)
assert commonmark_headings_to_bold(
thematic_break_ends_list_before_fence
) == ("- intro\n---\n ~~~\n # literal\n# still code")
# CRLF input follows the same thematic-break boundary rule.
thematic_break_ends_list_crlf = (
"- intro\r\n---\r\n ~~~\r\n # literal\r\n# still code"
)
assert commonmark_headings_to_bold(thematic_break_ends_list_crlf) == (
"- intro\r\n---\r\n ~~~\r\n # literal\r\n# still code"
)
# A tab at column zero reaches column four, creating indented code.
tab_at_column_zero_is_not_slack = "\t# literal"
assert (
commonmark_headings_to_bold(tab_at_column_zero_is_not_slack)
== tab_at_column_zero_is_not_slack
)
tab_at_column_zero_fence_is_not_slack = "\t~~~\ncode\n\t~~~\n# real"
assert commonmark_headings_to_bold(
tab_at_column_zero_fence_is_not_slack
) == ("\t~~~\ncode\n\t~~~\n**real**")
# A tab after a quote can remain within the three-column allowance.
tab_after_quote_is_slack = ">\t# literal"
assert commonmark_headings_to_bold(tab_after_quote_is_slack) == (
">\t**literal**"
)
# Tabs between nested quote markers use one column of marker padding.
tab_separated_nested_quote_fence = (
">\t>\t~~~\n>\t>\t# literal\n>\t>\t~~~\n>\t>\t# real"
)
assert commonmark_headings_to_bold(tab_separated_nested_quote_fence) == (
">\t>\t~~~\n>\t>\t# literal\n>\t>\t~~~\n>\t>\t**real**"
)
# Nested quote markers also work without separating spaces.
unspaced_nested_quote_fence = ">>~~~\n>>literal\n>>~~~\n>># real"
assert commonmark_headings_to_bold(unspaced_nested_quote_fence) == (
">>~~~\n>>literal\n>>~~~\n>>**real**"
)
# Tab-separated quote/list content uses indentation on continuation lines.
tab_separated_quote_list_fence = (
">\t-\tintro\n>\t ~~~\n>\t # literal\n>\t ~~~\n>\t# real"
)
assert commonmark_headings_to_bold(tab_separated_quote_list_fence) == (
">\t-\tintro\n>\t ~~~\n>\t # literal\n>\t ~~~\n>\t**real**"
)
# HTML blocks end lazy list paragraphs, making the next fence top-level.
html_block_ends_list_before_fence = (
"- intro\n