Updated the TODOs

This commit is contained in:
Dandaedre 2022-03-15 15:27:56 +01:00
parent 6e122d0c71
commit 2711c51eb7
2 changed files with 31 additions and 29 deletions

View File

@ -169,7 +169,7 @@ value = (quotes + pp.Word(pp.alphanums + r'.') + pp.match_previous_literal(quote
pp.common.fnumber)("value")
assignation = pp.Group(pp.common.identifier('var_name') + '=' + value('var_value'))("assignation")
text = pp.OneOrMore(pp.Word(pp.alphanums))('text').add_parse_action(of_type(TextToken))
http_characters = pp.Word(pp.alphanums + r'=+-_\/\\.:;!?%#@&*()[]{}~` ')
http_characters = pp.Word(pp.alphanums + r'=+-_\/\\.:;!?%#@&*()[]{}~` ') # Todo : Check common.url that can match any common url structure # noqa E501 # pylint: disable=line-too-long
# Composite elements
var = '[' + pp.delimitedList(assignation ^ value)("list_vars").set_name("list_vars") + ']'
@ -181,10 +181,11 @@ alias_element = ('@[' + pp.common.identifier('alias_name') + ']')("alias_element
expression = pp.Word(pp.alphanums + r'=+-_\'",;:!<> ')
html_insert = '{' + expression('html_insert') + '}'
structural_elements = \
(pp.Word('div') ^ pp.Word('article') ^ pp.Word('aside') ^ pp.Word('section'))('structural_element')
(pp.Word('div') ^ pp.Word('article') ^ pp.Word('aside') ^ pp.Word('section'))('structural_element') # TODO : Fixit: Word is "make a word with any of the characters in the string" whereas Literal is "make a word with a specific string" # noqa E501 (line too long)
# Optional elements
optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional")
optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional") # TODO : Make an optional token ? and maybe a htmlInsertToken and a varToken # noqa E501 (line too long)
# TODO :
# Everywhere : Avoid text at all costs since it is not a valid token, make a new token for it or use pp.SkipTo or (...)
@ -201,21 +202,25 @@ optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional")
# et_strikethrough | et_custom_span) + pp.Opt(enhanced_text)
# Multiline elements
# TODO: We decided for << instead of ~~ because it is easier to parse
se_start = ('~~' + structural_elements).add_parse_action(of_type(StructuralElementStartToken))
se_end = (structural_elements + '~~').add_parse_action(of_type(StructuralElementEndToken))
se = se_end | se_start # Structural element # TODO Check nomenclature
# Inline elements
il_link = '[' + ... + ']' + '(' + pp.quoted_string(http_characters, esc_character='\\') + ')'
il_link = pp.Literal('[') + ... + pp.Literal('](') + pp.QuotedString("'\"", esc_char='\\') + ')'
# Oneline elements
one_header = ('#' + ... + pps('#')).add_parse_action(of_type(HeaderToken)).addParseAction(of_type(HeaderToken))
# TODO: add a header level to the token
# TODO: one_header should match any number of '#'
one_header = (pp.Literal('#') + ... + pps(pp.Literal('#'))).add_parse_action(of_type(HeaderToken))
# TODO: Don't use "^" (longest match wins) use "|" (first match wins) # TODO: add a ("name") ?
one_olist = pp.line_start + \
((pp.Word(pp.nums) ^ pp.Word('#')) + '.' + ... + pp.line_end).add_parse_action(of_type(EtOlistToken))
# TODO: add a ("name")
# TODO: add a ("name") ?
one_ulist = pp.line_start + \
('-' + ... + pp.line_end).add_parse_action(of_type(EtUlistToken))
# TODO: add a ("name")
(pp.Literal('-') + ... + pp.line_end).add_parse_action(of_type(EtUlistToken))
# Final elements
enhanced_text = text # TODO: It's actually text or et_em or et_strong etc..., either recursive or repeated
@ -241,17 +246,6 @@ line_to_replace = pp.OneOrMore(pp.SkipTo(image ^ alias)('text').add_parse_action
if __name__ == '__main__': # pragma: no cover
pp.autoname_elements()
def find_color(new_time, old_time):
pct = percent(new_time, old_time)
if pct < 80:
return "red"
elif pct > 130:
return "green"
return "yellow"
def percent(new_time, old_time):
return round((old_time/new_time) * 100, 2)
list_strings = [
"Normal text",
"Normal text *em text*",
@ -261,8 +255,8 @@ if __name__ == '__main__': # pragma: no cover
"Normal text (#123) custom span text(#123)",
"**Strong text __underline__** normal text",
"Normal text **strong text *em text*** *em text **strong text*** normal text",
"~~div",
"div~~",
"<<div",
"div>>",
"[link text]('http://test.icule')",
"# header #",
"1. ordered list",

View File

@ -100,7 +100,7 @@ dict_advanced_syntax_input_and_expected_output = {
sy.EtCustomSpanToken(["#12"]), sy.TextToken(["test"]), sy.EtEmToken(["**"]),
sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]),
sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]), )),
("12. List", (sy.EtUlistToken(["12."]), sy.TextToken([" List"]), )),
("12. List of elements", (sy.EtUlistToken(["12", "List of elements"]), )),
("Test text with a link [link_name](link)", (sy.TextToken(["Test text with a link "]),
sy.HyperlinkToken(["link_name", "link"]), )),
("Test text with a link [link_name](link) and a *bold* text", (sy.TextToken(["Test text with a link "]),
@ -109,8 +109,16 @@ dict_advanced_syntax_input_and_expected_output = {
sy.TextToken(["bold"]), sy.EtEmToken(["*"]), )),
],
# Divs
"et_div": [
# Structural Elements
"se_start": [
# Matches a start of a structural element
("<<div", (sy.StructuralElementStartToken("div"), )),
],
"se_end": [
("div>>", (sy.StructuralElementEndToken("div"), )),
],
"se": [
# Matches a div element, must be at the beginning of the line, the closing div can be with arguments
# TODO: Implement a specific div token
("<<div", (sy.UnimplementedToken(["<<", "div"]), )),
@ -123,12 +131,12 @@ dict_advanced_syntax_input_and_expected_output = {
"one_olist": [
# Matches a one-level ordered list element, must be at the beginning of the line
# Drop the "." from the match
("12. Text", (sy.EtOlistToken(["12", sy.TextToken(["Text"])]), )),
("12. Text", (sy.EtOlistToken(["12", "Text"]), )),
],
"one_ulist": [
# Matches a one-level unordered list element, must be at the beginning of the line
# Drop the "-" from the match
("- Text", [sy.EtUlistToken([sy.TextToken(["Text"])]), ]),
("- Text", [sy.EtUlistToken(["-", "Text"])]),
],
# Headers
@ -148,7 +156,7 @@ dict_advanced_syntax_input_and_expected_output = {
],
# Tables
"table_row": [
# Matches a table element, must be at the beginning of the line # TODO: add TableCellToken?
# Matches a table element, must be at the beginning of the line
("| Text1 | Text2 |", (sy.TableRowToken(["|", "Text1", "|", "Text2", "|"]), )),
("| Text1 | Text2 | Text3 |", (sy.TableRowToken(["|", "Text1", "|", "Text2", "|", "Text3", "|"]), )),
("|2 Text1 | Text2 |", (sy.TableRowToken(["|2", "Text1", "|", "Text2", "|"]), )),
@ -259,7 +267,7 @@ def test_expression_matching(expression, to_parse):
assert expr.parse_string(string) is not None
@pytest.mark.xfail(reason="Not implemented yet.")
# @pytest.mark.xfail(reason="Not implemented yet.")
@pytest.mark.parametrize("expression, tokens", dict_advanced_syntax_input_and_expected_output.items())
def test_advanced_expression_and_token_creation(expression, tokens):
"""