diff --git a/src/bootstraparse/modules/syntax.py b/src/bootstraparse/modules/syntax.py index 9e4d4db..9d2d773 100644 --- a/src/bootstraparse/modules/syntax.py +++ b/src/bootstraparse/modules/syntax.py @@ -98,10 +98,6 @@ class TableRowToken(SemanticType): label = "table:row" -class TableHeaderToken(SemanticType): - label = "table:header" - - class TableCellToken(SemanticType): label = "table:cell" @@ -180,6 +176,7 @@ html_insert = '{' + expression('html_insert') + '}' # Optional elements optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional") +# 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 (...) # Enhanced text elements # TODO: Add all markups so that they can be parsed, they no longer need to be linked # et_em = ('*' + enhanced_text + '*')('em').add_parse_action(of_type(EtEmToken)) # et_strong = ('**' + enhanced_text + '**')('strong').add_parse_action(of_type(EtStrongToken)) @@ -189,11 +186,12 @@ optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional") # et_custom_span = \ # (custom_span + enhanced_text + pp.match_previous_literal(custom_span))('custom_span')\ # .add_parse_action(of_type(EtCustomSpanToken)) -# enhanced_text <<= (text | et_strong | et_em | et_underline | et_strikethrough | et_custom_span) + pp.Opt(enhanced_text) +# enhanced_text <== (text | et_strong | et_em | et_underline | +# et_strikethrough | et_custom_span) + pp.Opt(enhanced_text) # Multiline elements div_start = '~~' + text # TODO : It's not a text, rather a keyword and add ("name") and .add_parse_action(of_type(TextToken)) -div_end = text + '~~' +div_end = text + '~~' # TODO : Idem # Inline elements il_link = '[' + text + ']' + '(' + quotes + http_characters + pp.match_previous_literal(quotes) + ')' # Todo: change the quotes to quoted_string, get rid of text which was a placeholder diff --git a/tests/modules/test_syntax.py b/tests/modules/test_syntax.py index 3424070..a7944f8 100644 --- a/tests/modules/test_syntax.py +++ b/tests/modules/test_syntax.py @@ -3,13 +3,13 @@ import pytest import bootstraparse.modules.syntax as sy -# Dictionary of all label and associated token used in the language +# Dictionary of all label and associated token used in the Pre_parser list_of_token_types = { "alias": sy.AliasToken, "image": sy.ImageToken, } -# Dictionary of all lexical elements and a list of matching strings +# Dictionary of all lexical elements and a list of matching strings for the Pre_parser expressions_to_match = { # Base elements "quotes": ["'hi, there'", "'hi, there'"], @@ -48,30 +48,39 @@ expressions_to_match = { } +# Testing the parser lexical elements dict_advanced_syntax_input_and_expected_output = { # Enhanced text # TODO : Test optional inline args "et_em": [ + # Single em element, should only match the first "*" ("*", (sy.EtEmToken("*"), )), ], "et_strong": [ + # Single strong element, should only match the first "**" ("**", sy.EtEmToken("**"), ), ], "et_underline": [ + # Single underline element, should only match the first "__" ("__", (sy.EtUnderlineToken("__"), )), ], "et_strikethrough": [ + # Single strikethrough element, should only match the first "~~" ("~~", (sy.EtStrikethroughToken("~~"), )), ], "et_custom_span": [ + # Single custom span element, should only match the first "(#number)" ("(#12345)", (sy.EtCustomSpanToken("#12345"), )), ], "il_link": [ + # Single link element, should only match the first "[link_name](link)" + # TODO: Text tokens ? or Link token and hypelink token ? ("[text_link]('text://www.website.com/link.html')", - sy.UnimplementedToken("[text_link]('text://www.website.com/link.html')")) + sy.HyperlinkToken("[text_link]('text://www.website.com/link.html')")) ], # Enhanced Text "enhanced_text": [ + # Matches a line of text, with or without inline elements ("*test*", (sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"]))), ("**test**", (sy.EtEmToken(["**"]), sy.TextToken(["test"]), sy.EtEmToken(["**"]))), ("__test__", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]))), @@ -92,25 +101,35 @@ dict_advanced_syntax_input_and_expected_output = { sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]), )), ("12. List", (sy.EtUlistToken(["12."]), sy.TextToken([" List"]), )), - + ("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 "]), + sy.HyperlinkToken(["link_name", "link"]), + sy.TextToken([" and a "]), sy.EtEmToken(["*"]), + sy.TextToken(["bold"]), sy.EtEmToken(["*"]), )), ], # Divs "et_div": [ - ("<