Skip to content

Commit 74b7f3a

Browse files
thesmallstarclaude
andauthored
Fix heading with bold text producing malformed output (#11)
Both headings and bold map to `*` in Slack mrkdwn. When bold text appears inside a heading, the nested `*` markers produce malformed output like `**Step 1*: Description here*` instead of the correct `*Step 1: Description here*`. Suppress bold markers inside headings since the heading wrapper already provides bold formatting, making nested bold redundant. Fixes #10 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a5dfa11 commit 74b7f3a

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎src/slackify_markdown/slackify.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# Todo: Clean code before release.
1111
class SlackifyMarkdown(RendererHTML):
1212

13+
_in_heading = False
14+
1315
SUPPORTED_TOKENS = [
1416
"text",
1517
"inline",
@@ -112,6 +114,7 @@ def heading_open(
112114
options: Dict[str, Any],
113115
env: Dict[str, Any],
114116
) -> str:
117+
self.__class__._in_heading = True
115118
return "*"
116119

117120
def heading_close(
@@ -121,6 +124,7 @@ def heading_close(
121124
options: Dict[str, Any],
122125
env: Dict[str, Any],
123126
) -> str:
127+
self.__class__._in_heading = False
124128
return "*\n\n"
125129

126130
def strong_open(
@@ -130,6 +134,8 @@ def strong_open(
130134
options: Dict[str, Any],
131135
env: Dict[str, Any],
132136
) -> str:
137+
if self._in_heading:
138+
return ""
133139
return "*"
134140

135141
def strong_close(
@@ -139,6 +145,8 @@ def strong_close(
139145
options: Dict[str, Any],
140146
env: Dict[str, Any],
141147
) -> str:
148+
if self._in_heading:
149+
return ""
142150
return "*"
143151

144152
def em_open(

‎tests/test_convert.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def test_headings():
178178
assert slackify_markdown(mrkdown) == slack
179179

180180

181+
def test_heading_with_bold():
182+
assert slackify_markdown("### **Step 1**: Description here") == "*Step 1: Description here*\n\n"
183+
assert slackify_markdown("### **Step 1**") == "*Step 1*\n\n"
184+
assert slackify_markdown("# **Test**: text") == "*Test: text*\n\n"
185+
186+
181187
def test_bold():
182188
mrkdown = "**bold text**"
183189
slack = "*bold text*\n"

0 commit comments

Comments
 (0)