made things test-compliant, or tests thing-compliant

This commit is contained in:
vicky 2022-03-17 17:58:59 +01:00
parent a9b9d85ce1
commit f6e8897522
2 changed files with 19 additions and 29 deletions

View File

@ -194,6 +194,10 @@ optional = (
pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var")
)("optional").add_parse_action(of_type(OptionalToken))
# Inline elements
il_link = pp.Regex(
r"""\[(?P<text>.+)\]\(['"](?P<url>[a-zA-Z-_:\/=@#!%\?\d\(\)\.]+)['"]\)"""
).add_parse_action(of_type(HyperlinkToken))
# Enhanced text elements
et_em = pp.Literal('*')('em').add_parse_action(of_type(EtEmToken))
@ -203,22 +207,15 @@ et_strikethrough = pp.Literal('~~')('strikethrough').add_parse_action(of_type(Et
et_custom_span = (
pps('(#') + pp.Word(pp.nums)('span_id') + pps(')')
).set_name('custom_span').add_parse_action(of_type(EtCustomSpanToken))
markup = et_strong | et_em | et_strikethrough | et_underline | et_custom_span
# markup sums up all in-line elements
markup = il_link | et_strong | et_em | et_strikethrough | et_underline | et_custom_span
# Multiline elements
se_start = (pps('<<') + structural_elements).add_parse_action(of_type(StructuralElementStartToken))
se_end = (structural_elements + pps('>>')).add_parse_action(of_type(StructuralElementEndToken))
se = se_end | se_start # Structural element
# Inline elements
# [link text]('http://test.icule')
il_link = pp.common.url
# il_link = (
# pp.Literal('[') + pp.SkipTo('](')('text') + '](' +
# quotes + url_characters('url') + pp.match_previous_literal(quotes)
# + ')'
# ).add_parse_action(of_type(HyperlinkToken))
# Oneline elements
one_header = (
header_element + pp.SkipTo(pp.match_previous_literal(header_element))
@ -234,10 +231,9 @@ one_ulist = pp.line_start + (
).add_parse_action(of_type(EtUlistToken))
# Final elements
enhanced_text = pp.OneOrMore(markup + text)
# pp.SkipTo(markup)('text').add_parse_action(of_type(TextToken)) + markup |
# pp.SkipTo(pp.line_end)("text").add_parse_action(of_type(TextToken))
# )
enhanced_text = pp.ZeroOrMore(
markup | pp.SkipTo(markup)('text').add_parse_action(of_type(TextToken)) + markup
) + pp.Opt(pp.rest_of_line("text").add_parse_action(of_type(TextToken)))
##############################################################################
@ -253,7 +249,7 @@ line_to_replace = pp.OneOrMore(
pp.SkipTo(image ^ alias)('text').add_parse_action(of_type(TextToken))
^ image.add_parse_action(of_type(ImageToken))
^ alias.add_parse_action(of_type(AliasToken))
) ^ pp.SkipTo(pp.lineEnd)('text').add_parse_action(of_type(TextToken))
) ^ pp.rest_of_line('text').add_parse_action(of_type(TextToken))
##############################################################################
# Temporary tests
@ -261,12 +257,6 @@ line_to_replace = pp.OneOrMore(
if __name__ == '__main__': # pragma: no cover
pp.autoname_elements()
list_strings = [
"'http://test.icule'",
]
rich.inspect(il_link.parse_string(list_strings[0]))
if not os.path.exists('../../../dev_outputs/'):
os.mkdir('../../../dev_outputs/')
enhanced_text.create_diagram("../../../dev_outputs/diagram.html")

View File

@ -80,9 +80,9 @@ dict_advanced_syntax_input_and_expected_output = {
("(#12345)", (sy.EtCustomSpanToken(["12345"]), )),
],
"il_link": [
# Single link element, should only match the first "[link_name](link)"
# Single link element, should only match the first "[link_name]('link')"
("[text_link]('text://www.website.com/link.html')",
sy.HyperlinkToken("[text_link]('text://www.website.com/link.html')"))
[sy.HyperlinkToken(["[text_link]('text://www.website.com/link.html')"])])
],
# Enhanced Text
@ -107,11 +107,11 @@ dict_advanced_syntax_input_and_expected_output = {
sy.EtCustomSpanToken(["12"]), sy.TextToken(["test"]), sy.EtStrongToken(["**"]),
sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]),
sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]), )),
("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(["*"]),
("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(["*"]), )),
],
@ -212,7 +212,7 @@ list_of_text_input_and_readable_output = [
("**Bold**", "et_strong", "<text:strong = '**' />"),
("~~Strikethrough~~", "et_strikethrough", "<text:strikethrough = '~~' />"),
# ("Text *bold __underline__ still bold*", "enhanced_text", "<em: *><strong: **><underline: __><strikethrough: ~~>Text bold underline still bold</strikethrough :~~></underline :__></strong :**></em :*>"), # noqa E501 (line too long)
("[link]('http://www.google.com')", "il_link", "<link: [link](http://www.google.com)>"),
("[link]('http://www.google.com')", "il_link", "<hyperlink = '[link]('http://www.google.com')' />"),
# Structural elements
("<<div", "se", "<se:start = 'div' />"),