Simplify detecting and handling separators in format

This commit is contained in:
John Helmert
2019-07-24 11:27:59 -05:00
parent 59ac141528
commit e3853f9085

View File

@@ -19,6 +19,10 @@ class SubredditPage(Page):
BANNER = docs.BANNER_SUBREDDIT BANNER = docs.BANNER_SUBREDDIT
FOOTER = docs.FOOTER_SUBREDDIT FOOTER = docs.FOOTER_SUBREDDIT
# Format separators, used by _create_format and _draw_item_format for
# attribute handling logic
FORMAT_SEP = r"<>/{}[]()|_-~"
name = 'subreddit' name = 'subreddit'
def __init__(self, reddit, term, config, oauth, name): def __init__(self, reddit, term, config, oauth, name):
@@ -281,9 +285,9 @@ class SubredditPage(Page):
form = [] form = []
first = True first = True
# Split the list between %., newlines, and certain separator characters # Split the list between %., newlines, and separator characters to
# to treat them separately # treat them separately
format_list = re.split(r'(%.|[\n<>|\\])', format_string, re.DOTALL) format_list = re.split(r'(%.|[\n' + re.escape(self.FORMAT_SEP) + '])', format_string, re.DOTALL)
for item in format_list: for item in format_list:
# Use lambdas because the actual data to be used is only known at # Use lambdas because the actual data to be used is only known at
@@ -375,7 +379,7 @@ class SubredditPage(Page):
else: # Write something else that isn't in the data dict else: # Write something else that isn't in the data dict
# Make certain "separator" characters use the Separator # Make certain "separator" characters use the Separator
# attribute # attribute
if item in r"<>|\\": if item in self.FORMAT_SEP:
form.append((item, form.append((item,
lambda data: self.term.attr('Separator'), lambda data: self.term.attr('Separator'),
first)) first))