-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HTML formatting functions and update message handling
- Loading branch information
Showing
2 changed files
with
62 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import re | ||
|
||
def apply_hand_points(text: str) -> str: | ||
# Define the modified pattern to match '\n\*(?!\*)' | ||
pattern = r'(?<=\n)\*\s(?!\*)|^\*\s(?!\*)' | ||
|
||
replaced_text = re.sub(pattern, '👉 ', text) | ||
|
||
return replaced_text | ||
|
||
def apply_bold(text: str) -> str: | ||
# Pattern to match all markdown bold ** | ||
pattern = r'\*\*(.*?)\*\*' | ||
replaced_text = re.sub(pattern, r'<b>\1</b>', text) | ||
return replaced_text | ||
|
||
|
||
def apply_italic(text: str) -> str: | ||
# Pattern to match all markdown italic ** | ||
pattern = r'(?<!\*)\*(?!\*)(?!\*\*)(.*?)(?<!\*)\*(?!\*)' | ||
replaced_text = re.sub(pattern, r'<i>\1</i>', text) | ||
return replaced_text | ||
|
||
|
||
def apply_code(text: str) -> str: | ||
# Pattern to match all markdown code ```<any_text>.*``` | ||
pattern = r'```[\w]*\n((?:.|[\n])*?)\n```' | ||
replaced_text = re.sub(pattern, r'<pre>\1</pre>', text) | ||
return replaced_text | ||
|
||
|
||
# def apply_header(text: str) -> str: | ||
# # Pattern to match "### <any_text>" | ||
# pattern = r'### (.*)' | ||
# replaced_text = re.sub(pattern, r'<b><u>\1</u></b>', text) | ||
# return replaced_text | ||
|
||
|
||
def format_message(message: str) -> str: | ||
message = apply_bold(message) | ||
message = apply_italic(message) | ||
message = apply_hand_points(message) | ||
message = apply_code(message) | ||
# message = apply_header(message) | ||
return message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters