finished adding new elements, without names for now

This commit is contained in:
vicky 2022-03-15 13:01:35 +01:00
parent 74b953df78
commit 4099f615e4
1 changed files with 25 additions and 15 deletions

View File

@ -78,12 +78,20 @@ class EtUlistToken(SemanticType):
label = "text:ulist" label = "text:ulist"
class EtOlistToken(SemanticType):
label = "text:olist"
class HeaderToken(SemanticType): class HeaderToken(SemanticType):
label = "header" label = "header"
class StructuralElementToken(SemanticType): class StructuralElementStartToken(SemanticType):
label = "structural element" label = "se:start"
class StructuralElementEndToken(SemanticType):
label = "se:end"
class HyperlinkToken(SemanticType): class HyperlinkToken(SemanticType):
@ -172,12 +180,14 @@ image_element = ('@{' + pp.common.identifier('image_name') + '}')("image_element
alias_element = ('@[' + pp.common.identifier('alias_name') + ']')("alias_element") alias_element = ('@[' + pp.common.identifier('alias_name') + ']')("alias_element")
expression = pp.Word(pp.alphanums + r'=+-_\'",;:!<> ') expression = pp.Word(pp.alphanums + r'=+-_\'",;:!<> ')
html_insert = '{' + expression('html_insert') + '}' html_insert = '{' + expression('html_insert') + '}'
structural_elements = (pp.Word('div') ^ pp.Word('article') ^ pp.Word('aside') ^ pp.Word('section'))('structural_element') structural_elements = \
(pp.Word('div') ^ pp.Word('article') ^ pp.Word('aside') ^ pp.Word('section'))('structural_element')
# Optional elements # 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 : Everywhere : Avoid text at all costs since it is not a valid token, make a new token for it or use pp.SkipTo or (...) # 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 # 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_em = ('*' + enhanced_text + '*')('em').add_parse_action(of_type(EtEmToken))
# et_strong = ('**' + enhanced_text + '**')('strong').add_parse_action(of_type(EtStrongToken)) # et_strong = ('**' + enhanced_text + '**')('strong').add_parse_action(of_type(EtStrongToken))
@ -191,21 +201,21 @@ optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional")
# et_strikethrough | et_custom_span) + pp.Opt(enhanced_text) # et_strikethrough | et_custom_span) + pp.Opt(enhanced_text)
# Multiline elements # Multiline elements
se_start = '~~' + structural_elements # TODO : It's not a text, rather a keyword and add ("name") and .add_parse_action(of_type(TextToken)) se_start = ('~~' + structural_elements).add_parse_action(of_type(StructuralElementStartToken))
se_end = text + '~~' # TODO : Idem se_end = (structural_elements + '~~').add_parse_action(of_type(StructuralElementEndToken))
# Inline elements # Inline elements
il_link = '[' + text + ']' + '(' + quotes + http_characters + pp.match_previous_literal(quotes) + ')' il_link = '[' + ... + ']' + '(' + pp.quoted_string(http_characters, esc_character='\\') + ')'
# Todo: change the quotes to quoted_string and get rid of the text which was a placeholder
# Oneline elements # Oneline elements
one_header = ('#' + text + pps('#')).add_parse_action(of_type(HeaderToken)) one_header = ('#' + ... + pps('#')).add_parse_action(of_type(HeaderToken)).addParseAction(of_type(HeaderToken))
# 1 per hX or copy paste six times? # TODO: add a header level to the token
# TODO: add a header level to the token and get rid of the text which was a placeholder one_olist = pp.line_start + \
one_olist = pp.line_start + (pp.Word(pp.nums) ^ pp.Word('#')) + '.' + text ((pp.Word(pp.nums) ^ pp.Word('#')) + '.' + ... + pp.line_end).add_parse_action(of_type(EtOlistToken))
# TODO: add a ("name") and add .add_parse_action(of_type(TextToken)) # TODO: add a ("name")
one_ulist = pp.line_start + ('-' + text).add_parse_action(of_type(EtUlistToken)) one_ulist = pp.line_start + \
# TODO: add a ("name") and add .add_parse_action(of_type(TextToken)) and get rid of the text which was a placeholder ('-' + ... + pp.line_end).add_parse_action(of_type(EtUlistToken))
# TODO: add a ("name")
# Final elements # Final elements
enhanced_text = text # TODO: It's actually text or et_em or et_strong etc..., either recursive or repeated enhanced_text = text # TODO: It's actually text or et_em or et_strong etc..., either recursive or repeated