peter szemraj commited on
Commit
dfd722b
1 Parent(s): b406076

:art: format placeholders for tags

Browse files
Files changed (1) hide show
  1. utils.py +9 -3
utils.py CHANGED
@@ -2,7 +2,7 @@
2
  utils.py - Utility functions for the project.
3
  """
4
  import logging
5
-
6
 
7
  def postprocess(text: str):
8
  """
@@ -47,6 +47,7 @@ def make_email_link(
47
  subject: str = "Email subject - This was generated by Postbot",
48
  link_text: str = "click to open in your email client",
49
  body: str = None,
 
50
  ):
51
  """
52
  email_link - generate an email link
@@ -54,12 +55,17 @@ def make_email_link(
54
  Args:
55
  subject (str, optional): the subject of the email. Defaults to "Email subject - This was generated by Postbot".
56
  link_text (str, optional): the text of the link. Defaults to "click to open in your email client".
57
- body (_type_, optional): the body of the email. Defaults to None.
 
58
 
59
  Returns:
60
- str: the email link
61
  """
62
 
63
  if body is None:
64
  body = "hmm - no body. replace me"
 
 
 
 
65
  return f'<a href="mailto:%20?subject={subject}&body={body}">{link_text}</a>'
 
2
  utils.py - Utility functions for the project.
3
  """
4
  import logging
5
+ import re
6
 
7
  def postprocess(text: str):
8
  """
 
47
  subject: str = "Email subject - This was generated by Postbot",
48
  link_text: str = "click to open in your email client",
49
  body: str = None,
50
+ tag_placeholder: str = "PLACEHOLDER",
51
  ):
52
  """
53
  email_link - generate an email link
 
55
  Args:
56
  subject (str, optional): the subject of the email. Defaults to "Email subject - This was generated by Postbot".
57
  link_text (str, optional): the text of the link. Defaults to "click to open in your email client".
58
+ body (str, optional): the body of the email. Defaults to None.
59
+ tag_placeholder (str, optional): the placeholder for the tag. Defaults to "PLACEHOLDER".
60
 
61
  Returns:
62
+ str: the email link, in the form of an html link
63
  """
64
 
65
  if body is None:
66
  body = "hmm - no body. replace me"
67
+
68
+ # strip brackets and other HTML-tag characters from body with regex
69
+ body = re.sub(r"<[^>]*>", tag_placeholder, body)
70
+
71
  return f'<a href="mailto:%20?subject={subject}&body={body}">{link_text}</a>'