Compare commits
2 commits
1340eba1cb
...
e942b41917
| Author | SHA1 | Date | |
|---|---|---|---|
| e942b41917 | |||
| e64855b424 |
2 changed files with 45 additions and 35 deletions
78
lib/util.gd
78
lib/util.gd
|
|
@ -2,36 +2,47 @@ extends Object
|
|||
class_name Util
|
||||
|
||||
#region HTML RegEx and UnEscape HTML
|
||||
static var _img_re: RegEx = RegEx.create_from_string(r'<img[^>]*src=["\']([^"\']+)["\'][^>]*/?>')
|
||||
static var _h2_open_re: RegEx = RegEx.create_from_string(r'<h2[^>]*>')
|
||||
static var _p_open_re: RegEx = RegEx.create_from_string(r'<p[^>]*>')
|
||||
static var _ul_re: RegEx = RegEx.create_from_string(r'</?ul[^>]*>')
|
||||
static var _div_re: RegEx = RegEx.create_from_string(r'</?div[^>]*>')
|
||||
static var _any_tag_re: RegEx = RegEx.create_from_string(r'<[^>]*>')
|
||||
static var _html_replacements: Dictionary[String, String] = {
|
||||
"<": "<",
|
||||
">": ">",
|
||||
"&": "&",
|
||||
""": "\"",
|
||||
"'": "'",
|
||||
"'": "'",
|
||||
"/": "/",
|
||||
"`": "`",
|
||||
" ": " ",
|
||||
"©": "©",
|
||||
"®": "®",
|
||||
"€": "€",
|
||||
"£": "£",
|
||||
"¥": "¥",
|
||||
"–": "–",
|
||||
"—": "—",
|
||||
"‘": "‘",
|
||||
"’": "’",
|
||||
"“": "“",
|
||||
"”": "”",
|
||||
"…": "…",
|
||||
"•": "•"
|
||||
}
|
||||
static var _img_re: RegEx:
|
||||
get():
|
||||
if not _img_re: _img_re = RegEx.create_from_string(r'<img[^>]*src=["\']([^"\']+)["\'][^>]*/?>', true)
|
||||
return _img_re
|
||||
|
||||
static var _h2_open_re: RegEx:
|
||||
get():
|
||||
if not _h2_open_re: _h2_open_re = RegEx.create_from_string(r'<h2[^>]*>', true)
|
||||
return _h2_open_re
|
||||
|
||||
static var _p_open_re: RegEx:
|
||||
get():
|
||||
if not _p_open_re: _p_open_re = RegEx.create_from_string(r'<p[^>]*>', true)
|
||||
return _p_open_re
|
||||
|
||||
static var _ul_re: RegEx:
|
||||
get():
|
||||
if not _ul_re: _ul_re = RegEx.create_from_string(r'</?ul[^>]*>', true)
|
||||
return _ul_re
|
||||
|
||||
static var _div_re: RegEx:
|
||||
get():
|
||||
if not _div_re: _div_re = RegEx.create_from_string(r'</?div[^>]*>', true)
|
||||
return _div_re
|
||||
|
||||
static var _any_tag_re: RegEx:
|
||||
get():
|
||||
if not _any_tag_re: _any_tag_re = RegEx.create_from_string(r'<[^>]*>', true)
|
||||
return _any_tag_re
|
||||
|
||||
static var _html_replacements: Dictionary[String, String]:
|
||||
get():
|
||||
if not _html_replacements: _html_replacements = {
|
||||
"<": "<", ">": ">", "&": "&", """: "\"",
|
||||
"'": "'", "'": "'", "/": "/", "`": "`",
|
||||
" ": " ", "©": "©", "®": "®", "€": "€",
|
||||
"£": "£", "¥": "¥", "–": "–", "—": "—",
|
||||
"‘": "‘", "’": "’", "“": "“", "”": "”",
|
||||
"…": "…", "•": "•"
|
||||
}
|
||||
return _html_replacements
|
||||
#endregion
|
||||
|
||||
static func convert_html_to_bbcode(html: String) -> String:
|
||||
|
|
@ -70,9 +81,10 @@ static func convert_html_to_bbcode(html: String) -> String:
|
|||
|
||||
|
||||
static func html_unescape(text: String) -> String:
|
||||
for key in _html_replacements.keys():
|
||||
text = text.replace(key, _html_replacements[key])
|
||||
return text
|
||||
var new_text: String = String(text)
|
||||
for key: String in _html_replacements.keys():
|
||||
new_text = new_text.replace(key, _html_replacements[key])
|
||||
return new_text
|
||||
|
||||
static func resize_img_to_max_dim(img: Image, max_dim: int) -> Image:
|
||||
var width: int
|
||||
|
|
|
|||
|
|
@ -72,9 +72,7 @@ editor/game_oauth_setting="res://addons/twitcher/twitch_oauth_setting.tres"
|
|||
editor/project_preset=&"Other"
|
||||
editor/show_setup_on_startup=false
|
||||
logs/TwitchAuth="debug"
|
||||
logs/TwitchEventsubConfig="debug"
|
||||
logs/TwitchAPI="debug"
|
||||
logs/TwitchEventsub="debug"
|
||||
logs/TwitchChat="debug"
|
||||
logs/TwitchBot="debug"
|
||||
logs/TwitcherExtended="debug"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue