Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/slackify_markdown/slackify.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Todo: Clean code before release.
class SlackifyMarkdown(RendererHTML):

_in_heading = False

SUPPORTED_TOKENS = [
"text",
"inline",
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading