diff --git a/example_userfiles/doc.bpr b/example_userfiles/doc.bpr index d64c43e..e9b39c9 100644 --- a/example_userfiles/doc.bpr +++ b/example_userfiles/doc.bpr @@ -11,12 +11,12 @@ @[custom_permutation]{class="bouyou"}[number=44] -Oneline import @[tab_bnw]{class="sojek"} with three imports @[tab_color] @{image}{class="sojek dark" color="red"}[number=2] +- Oneline import @[tab_bnw]{class="sojek"} with three imports @[tab_color] @{image}{class="sojek dark" color="red"}[number=2] -add {{class}} at the end of an element for instant bootstrapyfication (class="") (class_insert) -add {html} at the end of an element to add something to your html markup element (style='border-top: 2px') (html_insert) -add [statement/str/float] at the end of an element to add something that must be interpreted by the parser - add [int] to modify the path for aliases and images (vuln[1] looks for vuln1.png), you can add multiple with commas for multiple images variations +- add {{class}} at the end of an element for instant bootstrapyfication (class="") (class_insert) +- add {html} at the end of an element to add something to your html markup element (style='border-top: 2px') (html_insert) +- add [statement/str/float] at the end of an element to add something that must be interpreted by the parser +- add [int] to modify the path for aliases and images (vuln[1] looks for vuln1.png), you can add multiple with commas for multiple images variations filler diff --git a/src/bootstraparse/modules/context_mngr.py b/src/bootstraparse/modules/context_mngr.py index 6e0a2f4..0017458 100644 --- a/src/bootstraparse/modules/context_mngr.py +++ b/src/bootstraparse/modules/context_mngr.py @@ -11,6 +11,7 @@ # container = BaseContainer() # container[number] -> The number element in the content # "class_insert" >> container[number] -> Get an element from one of the mapped methods +import rich from bootstraparse.modules import syntax, error_mngr, export from bootstraparse.modules.error_mngr import MismatchedContainerError, log_exception, log_message, LonelyOptionalError # noqa @@ -309,8 +310,11 @@ class TableCellContainer(BaseContainer): class LinebreakContainer(BaseContainer): - def export(self, _): # TODO: add lookahead for double linebreak to force break - return "\n" + def export(self, _): + if len(self.content) == 1: + return "\n" + return "
\n"*(len(self.content)-1) + """ @@ -358,7 +362,8 @@ class ContextManager: "list:ulist": ["list:ulist"], "list:olist": ["list:olist"], "table:row": ["table:separator", "table:row"], # TODO: Implement tables - "blockquotes": [] # TODO: Implement blockquotes + "blockquotes": [], # TODO: Implement blockquotes + "linebreak": ["linebreak"], } self.contextualised = False @@ -441,6 +446,7 @@ class ContextManager: return self.pile index = 0 line_number = 1 + while index < len(self.parsed_list): token = self.parsed_list[index] token.line_number = line_number @@ -450,11 +456,11 @@ class ContextManager: try: # Linebreaks if isinstance(token, syntax.Linebreak): - self.encapsulate(index, index) + # self.encapsulate(index, index) line_number += 1 # Pack the optionnal with the previous container if it exists (else raise error) - elif isinstance(token, syntax.OptionalToken): + if isinstance(token, syntax.OptionalToken): self.get_last_container_in_pile(index).optionals = token self.pile[index] = None diff --git a/src/bootstraparse/modules/syntax.py b/src/bootstraparse/modules/syntax.py index 6669cf2..e16c7c2 100644 --- a/src/bootstraparse/modules/syntax.py +++ b/src/bootstraparse/modules/syntax.py @@ -307,6 +307,10 @@ class BlockQuoteAuthorToken(SemanticType): class Linebreak(ExplicitSemanticType): label = "linebreak" + def __init__(self, content): + super().__init__(content) + self.content = [] + def to_container(self, filter_func=None): return self diff --git a/tests/modules/test_context_mngr.py b/tests/modules/test_context_mngr.py index ef5ed00..7877753 100644 --- a/tests/modules/test_context_mngr.py +++ b/tests/modules/test_context_mngr.py @@ -454,6 +454,21 @@ _token_list_with_expected_result = [ ], __GLk(1), ], + [ + [ + sy.Linebreak([]), + sy.Linebreak([]), + sy.Linebreak([]), + ], + [ + context_mngr.LinebreakContainer([ + sy.Linebreak([]), + sy.Linebreak([]), + sy.Linebreak([]), + ]), + ], + __GLk(1), + ], ] _zipped_token_list_with_expected_result = [ diff --git a/tests/modules/test_context_mngr_export.py b/tests/modules/test_context_mngr_export.py index fa25bff..5591d0e 100644 --- a/tests/modules/test_context_mngr_export.py +++ b/tests/modules/test_context_mngr_export.py @@ -200,11 +200,20 @@ _list_classes_expected_value = [ ], [ context_mngr.LinebreakContainer([ - sy.Linebreak([""]), + sy.Linebreak([]), ]), "\n", __GLk(1), ], + [ + context_mngr.LinebreakContainer([ + sy.Linebreak([]), + sy.Linebreak([]), + sy.Linebreak([]), + ]), + "
\n
\n", + __GLk(1), + ] ]