One function
SlackMarkdownConverter in fla9ua/markdown_to_mrkdwn
The author described this change as “Fix code block conversion issue #5\n\n- Add code block state tracking\n- Skip conversion inside code blocks\n- Add related test cases”. It counts as a record because the check below fails on the code as it stood at a016004e3 and passes on 9902c72dc, with nothing else changed between the two runs.
Projectfla9ua/markdown_to_mrkdwn
Fix saved2025-01-25
Sharing licenceMIT · LICENSE
Change size+10 −0
What the code was meant to do, written into the code itself as a docstring
A converter class to transform Markdown text into Slack's mrkdwn format. Attributes: encoding (str): The character encoding used for the conversion. patterns (List[Tuple[str, str]]): A list of regex patterns and their replacements.
The change
| 15 | 15 | encoding (str): The character encoding to use for the conversion. Default is 'utf-8'. | |
| 16 | 16 | """ | |
| 17 | 17 | self.encoding = encoding | |
| 18 | + | self.in_code_block = False | |
| 18 | 19 | self.patterns: List[Tuple[str, str]] = [ | |
| 19 | 20 | (r"^(\s*)- (.+)", r"\1• \2"), # Unordered list | |
| 20 | 21 | (r"!\[.*?\]\((.+?)\)", r"<\1>"), # Images to URL | |
| ⋯ | |||
| 66 | 67 | Returns: | |
| 67 | 68 | str: The converted line in Slack's mrkdwn format. | |
| 68 | 69 | """ | |
| 70 | + | # Toggle code block state | |
| 71 | + | if line.startswith("```"): | |
| 72 | + | self.in_code_block = not self.in_code_block | |
| 73 | + | return line | |
| 74 | + | ||
| 75 | + | # Skip conversion if inside code block | |
| 76 | + | if self.in_code_block: | |
| 77 | + | return line | |
| 78 | + | ||
| 69 | 79 | for pattern, replacement in self.patterns: | |
| 70 | 80 | line = re.sub(pattern, replacement, line, flags=re.MULTILINE) | |
| 71 | 81 | ||
The check that tells the two apart
fail→pass·tests/test_converter.py::TestSlackMarkdownConverter::test_code_block_with_cron
Check file tests/test_converter.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before ita016004e39578d9c1405ae12f002833f7eaf15c5
Broken version dated2025-01-03
Modulemarkdown_to_mrkdwn.converter
Units changedSlackMarkdownConverter
Fingerprint238968471d3cb282
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in fla9ua/markdown_to_mrkdwn
- 2024-12-12SlackMarkdownConverter