#21: Ukazatel na kontext se nyní propaguje i do OG.
This commit is contained in:
parent
89fa5e3416
commit
67a89d252b
4 changed files with 10 additions and 3 deletions
|
@ -100,7 +100,8 @@ class Context:
|
|||
#
|
||||
# Whenever a new context is created, its content should be eclosed in a group and vice-versa.
|
||||
class Group(Div):
|
||||
def __init__(self, *args, metadata={}, **kwargs):
|
||||
def __init__(self, *args, context:Context, metadata={}, **kwargs):
|
||||
self.metadata = metadata
|
||||
self.context = context
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ def main():
|
|||
|
||||
# Now wrap the document contents in a group, which is able to pop its language
|
||||
# setting out to TeX
|
||||
doc.content = [Group(*doc.content, metadata={"language":language})]
|
||||
doc.content = [Group(*doc.content, context=context, metadata={"language":language})]
|
||||
|
||||
# Initialize the image processor (this just keeps some basic state)
|
||||
imageProcessor = ImageProcessor(args.img_public_dir, args.img_web_path, args.img_cache_dir, *args.img_lookup_dirs)
|
||||
|
|
|
@ -20,6 +20,7 @@ class OutputGenerator:
|
|||
self.indent_str = indent_str
|
||||
self.indent_level = initial_indent_level
|
||||
self._at_start_of_line = True
|
||||
self.current_context = None
|
||||
|
||||
self.TYPE_DICT_MISC = {
|
||||
TableRow: self.generate_TableRow,
|
||||
|
@ -87,6 +88,9 @@ class OutputGenerator:
|
|||
}
|
||||
|
||||
def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]):
|
||||
if isinstance(e, Group):
|
||||
old_context = self.current_context
|
||||
self.current_context = e.context
|
||||
if isinstance(e, list):
|
||||
for el in e:
|
||||
self.generate(el)
|
||||
|
@ -101,6 +105,8 @@ class OutputGenerator:
|
|||
self.TYPE_DICT_MISC[type(e)](e)
|
||||
except KeyError:
|
||||
raise UnknownElementError(type(e))
|
||||
if isinstance(e, Group):
|
||||
self.current_context = old_context
|
||||
|
||||
def escape_special_chars(self, text: str) -> str:
|
||||
return text
|
||||
|
|
|
@ -72,7 +72,7 @@ def transform(e: Element, c: Context) -> Element:
|
|||
nContext = Context(includedDoc, path, c, trusted=trusted)
|
||||
language = includedDoc.get_metadata("language")
|
||||
includedDoc = includedDoc.walk(transform, nContext)
|
||||
e = Group(*includedDoc.content, metadata={"language": language})
|
||||
e = Group(*includedDoc.content, context=nContext, metadata={"language": language})
|
||||
|
||||
# Transform panflute's Quoted to custom FQuoted, see above.
|
||||
if isinstance(e, Quoted):
|
||||
|
|
Loading…
Reference in a new issue