Skip to content

Commit 2fdda1e

Browse files
committed
feat(markdown_to_bbcode): add strikethrough support
function convert_markdown_to_bbcode(markdown_text): +added strikethrough conversion (~~text~~ to [s]text[/s]) fix(markdown_to_bbcode): update inline code comment numbering function convert_markdown_to_bbcode(markdown_text): ~renumbered inline code comment (8 to 9) and blockquotes (9 to 10)
1 parent 4240c06 commit 2fdda1e

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

markdown_to_bbcode.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,23 +236,27 @@ def replace_links(match):
236236
# This prevents matching underscores within URLs or words like some_word
237237
bbcode_text = re.sub(r'(^|\s)(\*|_)(?!\2)(.*?)\2', r'\1[i]\3[/i]', bbcode_text)
238238

239-
# 8. Inline Code
239+
# 8. Strikethrough
240+
# Convert ~~text~~ to [s]text[/s]
241+
bbcode_text = re.sub(r'~~(.*?)~~', r'[s]\1[/s]', bbcode_text)
242+
243+
# 9. Inline Code
240244
# Convert `text` to [b]text[/b]
241245
bbcode_text = re.sub(r'`([^`\n]+)`', r'[b]\1[/b]', bbcode_text)
242246

243-
# 9. Blockquotes
247+
# 10. Blockquotes
244248
# Convert > Quote to [quote]Quote[/quote]
245249
def replace_blockquotes(match):
246250
quote = match.group(1)
247251
return f"[quote]{quote.strip()}[/quote]"
248252

249253
bbcode_text = re.sub(r'^>\s?(.*)', replace_blockquotes, bbcode_text, flags=re.MULTILINE)
250254

251-
# 10. Horizontal Rules
255+
# 11. Horizontal Rules
252256
# Convert --- or *** or ___ to [hr]
253257
bbcode_text = re.sub(r'^(\*\*\*|---|___)$', r'[hr]', bbcode_text, flags=re.MULTILINE)
254258

255-
# 11. Line Breaks
259+
# 12. Line Breaks
256260
# Convert two or more spaces at the end of a line to [br]
257261
bbcode_text = re.sub(r' {2,}\n', r'[br]\n', bbcode_text)
258262

0 commit comments

Comments
 (0)