removed outdated regexp and implemented parse_shortcuts_and_images

This commit is contained in:
vicky 2022-03-06 17:17:55 +01:00
parent 0a1749399e
commit 51b1b63ea7
1 changed files with 21 additions and 29 deletions

View File

@ -14,13 +14,7 @@ from rich.tree import Tree
# list of regexps # list of regexps
_rgx_import_file = regex.compile(r'::( ?\< ?(?P<file_name>[\w\-._/]+) ?\>[ \s]*)+') _rgx_import_file = regex.compile(r'::( ?\< ?(?P<file_name>[\w\-._/]+) ?\>[ \s]*)+')
# TODO: put this in syntax.py
# _rgx_shortcut_alias = r'@\[(?P<alias_name>[\w\-._/]+)\]'
# _rgx_shortcut_image = r'@{(?P<image_name>[\w\-._/]+)}'
# _rgx_shortcut_class = r'({(?P<class>[^}]+)})?'
# _rgx_shortcut_variable = r'(\[(?P<variables>[^\]]+)\])?'
# _rgx_alias = regex.compile(f'({_rgx_shortcut_alias}{_rgx_shortcut_class}{_rgx_shortcut_variable} ?)+')
# _rgx_image = regex.compile(f'({_rgx_shortcut_image}{_rgx_shortcut_class}{_rgx_shortcut_variable} ?)+')
class PreParser: class PreParser:
@ -184,7 +178,6 @@ class PreParser:
Return the file object with all file imports done Return the file object with all file imports done
:return: a filelike object with all file imports done :return: a filelike object with all file imports done
""" """
self.make_import_list() self.make_import_list()
# If the imports are already done, reset the cursor position and return the file # If the imports are already done, reset the cursor position and return the file
@ -214,37 +207,36 @@ class PreParser:
and replaces shortcuts and images calls with appropriate html and replaces shortcuts and images calls with appropriate html
:return: a table of occurrences and their lines :return: a table of occurrences and their lines
""" """
pass # TODO: deal with optionals
# line_count = 0 temp_file = self.file_with_all_imports
# temp_file = self.file_with_all_replacements temp_text = ''
# for line in self.readlines(): for line in temp_file.readlines():
# results = syntax.alias.parse_string(line) line_match = syntax.line_to_replace.parse_string(line)
# if results: for match in line_match:
# temp_file.writelines(self.get_alias_from_config(results.alias_name)) if match.label == 'text':
# else: temp_text = match.content.text
# results = syntax.inage.parse_string(line) elif match.label == 'image':
# if results: temp_text = self.get_image_from_config(match.content.image_name, match.content.optional)
# temp_file.writelines(self.get_picture_from_config(results.image_name)) elif match.label == 'alias':
# else: temp_text = self.get_alias_from_config(match.content.alias_name, match.content.optional)
# temp_file.writelines(line) self.file_with_all_replacements.write(temp_text)
# line_count += 1
# self.replacements_done = True
# return temp_file
def get_alias_from_config(self, shortcut): def get_alias_from_config(self, shortcut, optional):
""" """
Fetches shortcut paths from aliases.yaml Fetches shortcut paths from aliases.yaml
:return: the html to insert as a string :return: the html to insert as a string
:param shortcut: the id of the shortcut to fetch :param shortcut: id of the shortcut to fetch
:param optional: optional parameters along with alias
""" """
# return self.__env.config["aliases"][shortcut] # return self.__env.config["aliases"][shortcut]
return f'<h1>{shortcut}</h1>' return f'<h1>{shortcut}</h1>'
def get_picture_from_config(self, shortcut): def get_image_from_config(self, shortcut, optional):
""" """
Fetches picture paths from aliases.yaml Fetches image paths from aliases.yaml
:return: the html to insert as a string :return: html to insert as a string
:param shortcut: the id of the picture to fetch :param shortcut: the id of the picture to fetch
:param optional: optional parameters along with image
""" """
# return self.__env.config["images"][shortcut] # return self.__env.config["images"][shortcut]
return f'<img src="{shortcut}"/>' return f'<img src="{shortcut}"/>'