diff --git a/src/slackify_markdown/slackify.py b/src/slackify_markdown/slackify.py index 3b16803..240d84f 100644 --- a/src/slackify_markdown/slackify.py +++ b/src/slackify_markdown/slackify.py @@ -10,6 +10,8 @@ # Todo: Clean code before release. class SlackifyMarkdown(RendererHTML): + _in_heading = False + SUPPORTED_TOKENS = [ "text", "inline", @@ -112,6 +114,7 @@ def heading_open( options: Dict[str, Any], env: Dict[str, Any], ) -> str: + self.__class__._in_heading = True return "*" def heading_close( @@ -121,6 +124,7 @@ def heading_close( options: Dict[str, Any], env: Dict[str, Any], ) -> str: + self.__class__._in_heading = False return "*\n\n" def strong_open( @@ -130,6 +134,8 @@ def strong_open( options: Dict[str, Any], env: Dict[str, Any], ) -> str: + if self._in_heading: + return "" return "*" def strong_close( @@ -139,6 +145,8 @@ def strong_close( options: Dict[str, Any], env: Dict[str, Any], ) -> str: + if self._in_heading: + return "" return "*" def em_open( diff --git a/tests/test_convert.py b/tests/test_convert.py index 86343dc..9519f93 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -178,6 +178,12 @@ def test_headings(): assert slackify_markdown(mrkdown) == slack +def test_heading_with_bold(): + assert slackify_markdown("### **Step 1**: Description here") == "*Step 1: Description here*\n\n" + assert slackify_markdown("### **Step 1**") == "*Step 1*\n\n" + assert slackify_markdown("# **Test**: text") == "*Test: text*\n\n" + + def test_bold(): mrkdown = "**bold text**" slack = "*bold text*\n"