-
Notifications
You must be signed in to change notification settings - Fork 1
/
stringhelper.py
39 lines (32 loc) · 1 KB
/
stringhelper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import re
codeblock_regex = re.compile(r"```.*?```", re.DOTALL)
link_regex = re.compile(r"!?\[[^\n\]]*\]\(\s*[^\)\s]*\s*\)")
escape_trans = str.maketrans({
'\\': '\\\\',
'"': '\\"',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\b': '\\b',
'\f': '\\f'
})
def replace_references(x: str) -> str:
"""
replace_references replaces all @ sign in the given string with a placeholder @ which will
not trigger Github's markdown parser to reference the actual user.
"""
return x.replace("@", "@")
def format_to_quote(x: str) -> str:
"""
format_to_quote formats the string to a markdown quote.
args:
x: str - the string to be formatted
"""
return ">"+x.replace("\n", "\n>")
def escape_special_chars(s: str) -> str:
"""
escape_special_chars escapes the special characters in the given string to be used in a graphql query.
args:
s: str - the string to be escaped
"""
return s.translate(escape_trans)