From d87f3c127c6dba5271f9087302451dc774a4418c Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 15 Jun 2022 13:26:00 +0200 Subject: [PATCH] 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"]),