You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
from .nop_processor import NOPProcessor
|
|
from panflute import Div, Span, Null, Str, Plain, Quoted
|
|
from .context import Group, InlineGroup, BlockGroup
|
|
from .elements import FQuoted
|
|
from .whitespace import NBSP
|
|
from .nop_processor import ELCl
|
|
|
|
from typing import Callable
|
|
|
|
import sys
|
|
class PandocProcessor(NOPProcessor):
|
|
|
|
def get_posttransformers(self) -> list[Callable[[ELCl],ELCl]]:
|
|
return super().get_posttransformers()+[self.sanitize_attributes]
|
|
|
|
def sanitize_attributes(self, e: ELCl) -> ELCl:
|
|
if hasattr(e, "attributes"):
|
|
for key, value in e.attributes.items():
|
|
e.attributes[key] = str(value)
|
|
return e
|
|
|
|
def transform_Group(self, e: Group) -> Group:
|
|
e.content = self.transform(e.content)
|
|
return Div(*e.content)
|
|
|
|
def transform_InlineGroup(self, e: InlineGroup) -> InlineGroup:
|
|
e.content = self.transform(e.content)
|
|
return Span(*e.content)
|
|
|
|
def transform_BlockGroup(self, e: BlockGroup) -> BlockGroup:
|
|
e.content = self.transform(e.content)
|
|
return Div(*e.content)
|
|
|
|
def transform_Null(self, e: Null):
|
|
return Plain(Str(""))
|
|
|
|
def transform_FQuoted(self, e: FQuoted) -> Quoted:
|
|
return Quoted(*e.content)
|
|
|
|
def transform_NBSP(self, e: NBSP) -> Str:
|
|
return Str(" ") # Unicode nbsp
|
|
|