implemented header, display and custom_spans, added label_container for _to_container
This commit is contained in:
parent
fef6908165
commit
0186be993f
|
|
@ -188,7 +188,10 @@ class EtStrikethroughContainer(BaseContainer):
|
||||||
|
|
||||||
class EtCustomSpanContainer(BaseContainer):
|
class EtCustomSpanContainer(BaseContainer):
|
||||||
type = "inline_elements"
|
type = "inline_elements"
|
||||||
subtype = "custom_0" # future: add logic
|
|
||||||
|
def export(self, exm):
|
||||||
|
self.subtype = "custom_" + self.content[0].content[0]
|
||||||
|
return super().export(exm)
|
||||||
|
|
||||||
|
|
||||||
class EtUlistContainer(BaseContainer):
|
class EtUlistContainer(BaseContainer):
|
||||||
|
|
@ -207,10 +210,9 @@ class HyperLinkContainer(BaseContainer):
|
||||||
type = "inline_elements"
|
type = "inline_elements"
|
||||||
subtype = "link"
|
subtype = "link"
|
||||||
|
|
||||||
def __init__(self, content=None, optionals=None, others=None):
|
def export(self, exm):
|
||||||
super().__init__(content, optionals, others)
|
self.others["url"] = self.content[0].content.url
|
||||||
self.map['url'] = ""
|
return super().export(exm)
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# class IlImageContainer(BaseContainer):
|
# class IlImageContainer(BaseContainer):
|
||||||
|
|
@ -229,20 +231,20 @@ class HeaderContainer(BaseContainer):
|
||||||
type = "structural_elements"
|
type = "structural_elements"
|
||||||
subtype = "header"
|
subtype = "header"
|
||||||
|
|
||||||
def __init__(self, content=None, optionals=None, others=None):
|
def export(self, exm):
|
||||||
super().__init__(content, optionals, others)
|
self.others = {}
|
||||||
self.map['header_level'] = ''
|
self.others["header_level"] = len(self.content[0].content[0])
|
||||||
pass
|
return super().export(exm)
|
||||||
|
|
||||||
|
|
||||||
class DisplayContainer(BaseContainer):
|
class DisplayContainer(BaseContainer):
|
||||||
type = "structural_elements"
|
type = "structural_elements"
|
||||||
subtype = "display"
|
subtype = "display"
|
||||||
|
|
||||||
def __init__(self, content=None, optionals=None, others=None):
|
def export(self, exm):
|
||||||
super().__init__(content, optionals, others)
|
self.others = {}
|
||||||
self.map['display_level'] = ""
|
self.others["display_level"] = len(self.content[0].content[0])
|
||||||
pass
|
return super().export(exm)
|
||||||
|
|
||||||
|
|
||||||
class TableSeparatorContainer(BaseContainer):
|
class TableSeparatorContainer(BaseContainer):
|
||||||
|
|
@ -298,10 +300,7 @@ _to_container = {
|
||||||
"list:olist": EtOlistContainer,
|
"list:olist": EtOlistContainer,
|
||||||
"header": HeaderContainer,
|
"header": HeaderContainer,
|
||||||
"display": DisplayContainer,
|
"display": DisplayContainer,
|
||||||
"se:start:div": SeContainer,
|
"se:start": SeContainer,
|
||||||
"se:start:article": SeContainer,
|
|
||||||
"se:start:aside": SeContainer,
|
|
||||||
"se:start:section": SeContainer,
|
|
||||||
"hyperlink": HyperLinkContainer,
|
"hyperlink": HyperLinkContainer,
|
||||||
"linebreak": LinebreakContainer,
|
"linebreak": LinebreakContainer,
|
||||||
"table:row": TableRowContainer,
|
"table:row": TableRowContainer,
|
||||||
|
|
@ -362,7 +361,7 @@ class ContextManager:
|
||||||
level="CRITICAL"
|
level="CRITICAL"
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
container = _to_container[pile_start.label]() # noqa : F821
|
container = _to_container[pile_start.label_container]() # noqa : F821
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log_exception(
|
log_exception(
|
||||||
KeyError(f"Element {pile_start.label} not in dictionary of tokens-containers correspondences."),
|
KeyError(f"Element {pile_start.label} not in dictionary of tokens-containers correspondences."),
|
||||||
|
|
@ -434,13 +433,13 @@ class ContextManager:
|
||||||
elif isinstance(token, syntax.FinalSemanticType): # one-liners
|
elif isinstance(token, syntax.FinalSemanticType): # one-liners
|
||||||
self.encapsulate(index, index)
|
self.encapsulate(index, index)
|
||||||
|
|
||||||
elif token.counterpart() in self.matched_elements: # found a matching token in encountered tokens
|
elif token.counterpart() in self.matched_elements and len(self.matched_elements[token.counterpart()]) != 0: # found a matching token in encountered tokens
|
||||||
self.encapsulate(self._get_matched(token.counterpart()), index)
|
self.encapsulate(self._get_matched(token.counterpart()), index)
|
||||||
|
|
||||||
elif isinstance(token, syntax.ClosedSemanticType): # error if closing token does not have a start
|
elif isinstance(token, syntax.ClosedSemanticType): # error if closing token does not have a start
|
||||||
raise MismatchedContainerError(token)
|
raise MismatchedContainerError(token)
|
||||||
|
|
||||||
else: # starting token by default (can cause unintended behaviours on bad implementations)
|
else: # starting token by default (can cause unintended behaviours on bad implementations) # TODO: remove this default behaviour, error instead
|
||||||
self._add_matched(token.label, index)
|
self._add_matched(token.label, index)
|
||||||
except MismatchedContainerError as e:
|
except MismatchedContainerError as e:
|
||||||
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Be more specific.
|
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Be more specific.
|
||||||
|
|
@ -520,6 +519,7 @@ class ContextManager:
|
||||||
e.print_all()
|
e.print_all()
|
||||||
else:
|
else:
|
||||||
print("> " + str(e))
|
print("> " + str(e))
|
||||||
|
print("Matched elements:" + self.matched_elements)
|
||||||
|
|
||||||
|
|
||||||
# Defines all methods to manage the context of the parser as a file is being parsed
|
# Defines all methods to manage the context of the parser as a file is being parsed
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue