From 0f55dcd523c75895da296f3dcf349306c264d7d5 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 15 Jun 2022 13:15:03 +0200 Subject: [PATCH 1/2] Hotfix on the syntax with ulits --- src/bootstraparse/modules/syntax.py | 4 ++-- tests/modules/test_syntax.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bootstraparse/modules/syntax.py b/src/bootstraparse/modules/syntax.py index db1cc63..ba225e7 100644 --- a/src/bootstraparse/modules/syntax.py +++ b/src/bootstraparse/modules/syntax.py @@ -535,12 +535,12 @@ one_display = ( pp.Opt(optional) ).add_parse_action(of_type(DisplayToken)) one_olist = pp.line_start + ( - pps(pp.Literal('#.')) + ( + pps(pp.Combine(pp.line_start + pp.Literal('#.'))) + ( (pp.SkipTo(optional)('text').add_parse_action(reparse(enhanced_text)) + optional) | enhanced_text) ).add_parse_action(of_type(EtOlistToken)) one_ulist = pp.line_start + ( - pps(pp.Literal('-')) + ( + pps(pp.Combine(pp.line_start + pp.Literal('-'))) + ( (pp.SkipTo(optional)('text').add_parse_action(reparse(enhanced_text)) + optional) | enhanced_text) ).add_parse_action(of_type(EtUlistToken)) diff --git a/tests/modules/test_syntax.py b/tests/modules/test_syntax.py index f713087..c8c7806 100644 --- a/tests/modules/test_syntax.py +++ b/tests/modules/test_syntax.py @@ -524,6 +524,7 @@ dict_advanced_syntax_input_and_expected_output = { ), __GL()), ("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GL()), ("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GL()), + (" - Non ulist", (sy.TextToken(["- Non ulist"]),), __GL()), ("div>>", (sy.StructuralElementEndToken(["div"]),), __GL()), ("#. Text with *em* and __underline__ and {arguments}{{super-arguments}}[a=1, c=2,'ui']", ( sy.EtOlistToken([ @@ -666,6 +667,7 @@ list_of_text_input_and_readable_output = [ # Other Mostly for testing and coverage ("'", "quotes", "'"), + (" -", "line", "-"), ] From d87f3c127c6dba5271f9087302451dc774a4418c Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 15 Jun 2022 13:26:00 +0200 Subject: [PATCH 2/2] Added a couple of things inside << and >> detection (body, nav, header) --- src/bootstraparse/modules/syntax.py | 9 ++++++--- tests/modules/test_context_mngr.py | 15 +++++++++++++++ tests/modules/test_syntax.py | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/bootstraparse/modules/syntax.py b/src/bootstraparse/modules/syntax.py index db1cc63..695675a 100644 --- a/src/bootstraparse/modules/syntax.py +++ b/src/bootstraparse/modules/syntax.py @@ -267,12 +267,12 @@ class DisplayToken(FinalSemanticType): class StructuralElementStartToken(AddFirstElementToLabel, OpenedSemanticType, TokensToMatch): - """<>""" + """div|article|section|aside|header|body|nav>>""" label = "se:end" def counterpart(self): @@ -470,7 +470,10 @@ structural_elements = ( pp.CaselessLiteral('div') | pp.CaselessLiteral('article') | pp.CaselessLiteral('aside') | - pp.CaselessLiteral('section') + pp.CaselessLiteral('section') | + pp.CaselessLiteral('header') | + pp.CaselessLiteral('body') | + pp.CaselessLiteral('nav') )('structural_element') header_element = pp.Word('#') display_element = pp.Word('!') diff --git a/tests/modules/test_context_mngr.py b/tests/modules/test_context_mngr.py index 895cbd6..ab5674d 100644 --- a/tests/modules/test_context_mngr.py +++ b/tests/modules/test_context_mngr.py @@ -64,6 +64,21 @@ _token_list_with_expected_result = [ ], __GLk(1), ], + [ + [ + sy.StructuralElementStartToken(["header"]), + sy.TextToken(["1"]), + sy.StructuralElementEndToken(["header"]), + ], + [ + context_mngr.SeContainer([ + sy.StructuralElementStartToken(["header"]), + context_mngr.TextContainer([sy.TextToken(["1"])]), + sy.StructuralElementEndToken(["header"]) + ]), + ], + __GLk(1), + ], [ [ sy.EtEmToken(["*"]), diff --git a/tests/modules/test_syntax.py b/tests/modules/test_syntax.py index f713087..8628a96 100644 --- a/tests/modules/test_syntax.py +++ b/tests/modules/test_syntax.py @@ -525,6 +525,7 @@ dict_advanced_syntax_input_and_expected_output = { ("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GL()), ("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GL()), ("div>>", (sy.StructuralElementEndToken(["div"]),), __GL()), + ("body>>", (sy.StructuralElementEndToken(["body"]),), __GL()), ("#. Text with *em* and __underline__ and {arguments}{{super-arguments}}[a=1, c=2,'ui']", ( sy.EtOlistToken([ sy.TextToken(["Text with"]),