El Famoso br fix

This commit is contained in:
Maximilien Rigaut 2022-06-07 07:14:56 +02:00
parent e7d3d94847
commit ea035c8289
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
5 changed files with 45 additions and 11 deletions

View File

@ -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

View File

@ -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 "<br />\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

View File

@ -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

View File

@ -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 = [

View File

@ -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([]),
]),
"<br />\n<br />\n",
__GLk(1),
]
]