Test exact_match option for fence closing.
| 84 | |
| 85 | |
| 86 | class TestExactMatch: |
| 87 | """Test exact_match option for fence closing.""" |
| 88 | |
| 89 | def _make_exact_md(self) -> MarkdownIt: |
| 90 | """Create MarkdownIt with exact-match colon fence.""" |
| 91 | md = MarkdownIt() |
| 92 | colon_rule = make_fence_rule( |
| 93 | markers=(":",), |
| 94 | token_type="colon_fence", |
| 95 | disallow_marker_in_info=(), |
| 96 | exact_match=True, |
| 97 | ) |
| 98 | md.block.ruler.before( |
| 99 | "fence", |
| 100 | "colon_fence", |
| 101 | colon_rule, |
| 102 | {"alt": ["paragraph", "reference", "blockquote", "list"]}, |
| 103 | ) |
| 104 | return md |
| 105 | |
| 106 | def test_exact_match_same_length(self): |
| 107 | """Closing fence with same length closes the block.""" |
| 108 | md = self._make_exact_md() |
| 109 | tokens = md.parse(":::\nfoo\n:::\n") |
| 110 | assert len(tokens) == 1 |
| 111 | assert tokens[0].type == "colon_fence" |
| 112 | assert tokens[0].content == "foo\n" |
| 113 | |
| 114 | def test_exact_match_longer_no_close(self): |
| 115 | """Closing fence with more markers does NOT close (exact match required).""" |
| 116 | md = self._make_exact_md() |
| 117 | tokens = md.parse(":::\nfoo\n::::\n:::\n") |
| 118 | assert len(tokens) == 1 |
| 119 | assert tokens[0].type == "colon_fence" |
| 120 | # :::: is content, not a closer; ::: at the end is the real closer |
| 121 | assert "::::" in tokens[0].content |
| 122 | assert tokens[0].content == "foo\n::::\n" |
| 123 | |
| 124 | def test_exact_match_shorter_no_close(self): |
| 125 | """Closing fence with fewer markers does NOT close (exact match required).""" |
| 126 | md = self._make_exact_md() |
| 127 | tokens = md.parse("::::\nfoo\n:::\nbar\n::::\n") |
| 128 | assert len(tokens) == 1 |
| 129 | assert tokens[0].type == "colon_fence" |
| 130 | assert ":::" in tokens[0].content |
| 131 | assert tokens[0].content == "foo\n:::\nbar\n" |
| 132 | |
| 133 | def test_nesting_pattern(self): |
| 134 | """Demonstrate nested fences with exact match (outer 4, inner 3).""" |
| 135 | md = self._make_exact_md() |
| 136 | tokens = md.parse( |
| 137 | "::::{note}\nouter\n:::{warning}\ninner\n:::\nouter again\n::::\n" |
| 138 | ) |
| 139 | assert len(tokens) == 1 |
| 140 | assert tokens[0].type == "colon_fence" |
| 141 | assert tokens[0].info == "{note}" |
| 142 | assert tokens[0].markup == "::::" |
| 143 | # The inner ::: fence is captured as content |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…