|
@ -2,6 +2,7 @@ from panflute import Element, ListContainer, Inline, Block |
|
|
from panflute import Cite, Code, Emph, Image, LineBreak, Link, Math, Note, Quoted, RawInline, SmallCaps, SoftBreak, Space, Span, Str, Strikeout, Strong, Subscript, Superscript, Underline |
|
|
from panflute import Cite, Code, Emph, Image, LineBreak, Link, Math, Note, Quoted, RawInline, SmallCaps, SoftBreak, Space, Span, Str, Strikeout, Strong, Subscript, Superscript, Underline |
|
|
from panflute import BlockQuote, BulletList, Citation, CodeBlock, Definition, DefinitionItem, DefinitionList, Div, Figure, Header, HorizontalRule, LineBlock, LineItem, ListItem, MetaBlocks, MetaBool, MetaInlines, MetaList, MetaMap, MetaString, Null, OrderedList, Para, Plain, RawBlock, Table, TableBody, TableFoot, TableHead |
|
|
from panflute import BlockQuote, BulletList, Citation, CodeBlock, Definition, DefinitionItem, DefinitionList, Div, Figure, Header, HorizontalRule, LineBlock, LineItem, ListItem, MetaBlocks, MetaBool, MetaInlines, MetaList, MetaMap, MetaString, Null, OrderedList, Para, Plain, RawBlock, Table, TableBody, TableFoot, TableHead |
|
|
from panflute import TableRow, TableCell, Caption, Doc |
|
|
from panflute import TableRow, TableCell, Caption, Doc |
|
|
|
|
|
from panflute import MetaValue |
|
|
from typing import Union, Callable |
|
|
from typing import Union, Callable |
|
|
|
|
|
|
|
|
from .whitespace import NBSP |
|
|
from .whitespace import NBSP |
|
@ -53,12 +54,6 @@ class OutputGenerator: |
|
|
Header: self.generate_Header, |
|
|
Header: self.generate_Header, |
|
|
HorizontalRule: self.generate_HorizontalRule, |
|
|
HorizontalRule: self.generate_HorizontalRule, |
|
|
LineBlock: self.generate_LineBlock, |
|
|
LineBlock: self.generate_LineBlock, |
|
|
MetaBlocks: self.generate_MetaBlocks, |
|
|
|
|
|
MetaBool: self.generate_MetaBool, |
|
|
|
|
|
MetaInlines: self.generate_MetaInlines, |
|
|
|
|
|
MetaList: self.generate_MetaList, |
|
|
|
|
|
MetaMap: self.generate_MetaMap, |
|
|
|
|
|
MetaString: self.generate_MetaString, |
|
|
|
|
|
Null: self.generate_Null, |
|
|
Null: self.generate_Null, |
|
|
OrderedList: self.generate_OrderedList, |
|
|
OrderedList: self.generate_OrderedList, |
|
|
Para: self.generate_Para, |
|
|
Para: self.generate_Para, |
|
@ -97,6 +92,14 @@ class OutputGenerator: |
|
|
InlineGroup: self.generate_InlineGroup |
|
|
InlineGroup: self.generate_InlineGroup |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.TYPE_DICT_META = { |
|
|
|
|
|
MetaBlocks: self.generate_MetaBlocks, |
|
|
|
|
|
MetaBool: self.generate_MetaBool, |
|
|
|
|
|
MetaInlines: self.generate_MetaInlines, |
|
|
|
|
|
MetaMap: self.generate_MetaMap, |
|
|
|
|
|
MetaString: self.generate_MetaString, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]): |
|
|
def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]): |
|
|
if isinstance(e, Group): |
|
|
if isinstance(e, Group): |
|
|
old_context = self.context |
|
|
old_context = self.context |
|
@ -109,6 +112,10 @@ class OutputGenerator: |
|
|
self.generate_Inline(e) |
|
|
self.generate_Inline(e) |
|
|
elif isinstance(e, Block): |
|
|
elif isinstance(e, Block): |
|
|
self.generate_Block(e) |
|
|
self.generate_Block(e) |
|
|
|
|
|
elif isinstance(e, MetaValue): |
|
|
|
|
|
self.generate_MetaValue(e) |
|
|
|
|
|
elif isinstance(e, MetaList): |
|
|
|
|
|
self.generate_MetaList(e) |
|
|
else: |
|
|
else: |
|
|
try: |
|
|
try: |
|
|
self.TYPE_DICT_MISC[type(e)](e) |
|
|
self.TYPE_DICT_MISC[type(e)](e) |
|
@ -231,6 +238,31 @@ class OutputGenerator: |
|
|
for el in e: |
|
|
for el in e: |
|
|
self.generate(el) |
|
|
self.generate(el) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaList(self, e: MetaList): |
|
|
|
|
|
for child in e: |
|
|
|
|
|
self.generate(child) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaValue(self, e: MetaValue): |
|
|
|
|
|
try: |
|
|
|
|
|
self.TYPE_DICT_META[type(e)](e) |
|
|
|
|
|
except KeyError: |
|
|
|
|
|
self.generate(e.content) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaBlocks(self, e: MetaBlocks): |
|
|
|
|
|
self.generate(e.content) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaInlines(self, e: MetaInlines): |
|
|
|
|
|
self.generate(e.content) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaBool(self, e: MetaBool): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaMap(self, e: MetaMap): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaString(self, e: MetaString): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
def generate_Inline(self, e: Inline): |
|
|
def generate_Inline(self, e: Inline): |
|
|
self.TYPE_DICT_INLINE[type(e)](e) |
|
|
self.TYPE_DICT_INLINE[type(e)](e) |
|
|
|
|
|
|
|
@ -370,24 +402,6 @@ class OutputGenerator: |
|
|
def generate_ListItem(self, e: ListItem): |
|
|
def generate_ListItem(self, e: ListItem): |
|
|
self.generate_simple_tag(e) |
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
def generate_MetaBlocks(self, e: MetaBlocks): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaBool(self, e: MetaBool): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaInlines(self, e: MetaInlines): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaList(self, e: MetaList): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaMap(self, e: MetaMap): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_MetaString(self, e: MetaString): |
|
|
|
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
|
|
|
def generate_OrderedList(self, e: OrderedList): |
|
|
def generate_OrderedList(self, e: OrderedList): |
|
|
self.generate_simple_tag(e) |
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
@ -416,7 +430,11 @@ class OutputGenerator: |
|
|
self.generate_simple_tag(e) |
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
|
|
|
def generate_Doc(self, e: Doc): |
|
|
def generate_Doc(self, e: Doc): |
|
|
|
|
|
if "header_content" in e.metadata: |
|
|
|
|
|
self.generate(e.metadata["header_content"]) |
|
|
self.generate_simple_tag(e) |
|
|
self.generate_simple_tag(e) |
|
|
|
|
|
if "footer_content" in e.metadata: |
|
|
|
|
|
self.generate(e.metadata["footer_content"]) |
|
|
|
|
|
|
|
|
def generate_BlockGroup(self, e: BlockGroup): |
|
|
def generate_BlockGroup(self, e: BlockGroup): |
|
|
self.generate_simple_tag(e) |
|
|
self.generate_simple_tag(e) |
|
|