diff --git a/src/formatitko/elements.py b/src/formatitko/elements.py index 17840f4..1ce1526 100644 --- a/src/formatitko/elements.py +++ b/src/formatitko/elements.py @@ -1,4 +1,4 @@ -from panflute import Quoted +from panflute import Quoted, Emph from .command import Command, InlineCommand, BlockCommand, CodeCommand @@ -14,3 +14,5 @@ class FQuoted(Quoted): del kwargs["style"] super().__init__(*args, **kwargs) +class Slanted(Emph): + pass diff --git a/src/formatitko/nop_processor.py b/src/formatitko/nop_processor.py index 8218b2e..3c8af97 100644 --- a/src/formatitko/nop_processor.py +++ b/src/formatitko/nop_processor.py @@ -6,7 +6,7 @@ from panflute import MetaValue from typing import Union, Callable from .whitespace import NBSP -from .elements import FQuoted +from .elements import FQuoted, Slanted from .context import Group, InlineGroup, BlockGroup, Context from .whitespace import Whitespace from .command import BlockCommand, InlineCommand, CodeCommand, Command @@ -69,6 +69,7 @@ class NOPProcessor: Cite: self.transform_Cite, Code: self.transform_Code, Emph: self.transform_Emph, + Slanted: self.transform_Slanted, Image: self.transform_Image, LineBreak: self.transform_LineBreak, Link: self.transform_Link, @@ -263,6 +264,10 @@ class NOPProcessor: e.content = self.transform(e.content) return e + def transform_Slanted(self, e: Slanted) -> Slanted: + e.content = self.transform(e.content) + return e + def transform_Link(self, e: Link) -> Link: e.content = self.transform(e.content) return e diff --git a/src/formatitko/output_generator.py b/src/formatitko/output_generator.py index 8e854a3..022228e 100644 --- a/src/formatitko/output_generator.py +++ b/src/formatitko/output_generator.py @@ -7,7 +7,7 @@ from panflute import stringify from typing import Union, Callable from .whitespace import NBSP -from .elements import FQuoted +from .elements import FQuoted, Slanted from .context import Group, InlineGroup, BlockGroup, Context @@ -108,6 +108,7 @@ class OutputGenerator: Cite: self.generate_Cite, Code: self.generate_Code, Emph: self.generate_Emph, + Slanted: self.generate_Slanted, Image: self.generate_Image, LineBreak: self.generate_LineBreak, Link: self.generate_Link, @@ -376,6 +377,9 @@ class OutputGenerator: def generate_Emph(self, e: Emph): self.generate_simple_tag(e) + def generate_Slanted(self, e: Slanted): + self.generate_Emph(e) + def generate_Image(self, e: Image): self.generate_simple_tag(e) diff --git a/src/formatitko/tex_generator.py b/src/formatitko/tex_generator.py index 5a83d8f..0b736db 100644 --- a/src/formatitko/tex_generator.py +++ b/src/formatitko/tex_generator.py @@ -179,6 +179,11 @@ class UCWTexGenerator(OutputGenerator): self._italic-=1 self.write(r"}") + def generate_Slanted(self, e: Emph): + self.write(r"{\sl{}") + self.generate(e.content) + self.write(r"}") + def generate_Strong(self, e: Strong): if self._italic > 0: self.write(r"{\bi{}") diff --git a/src/formatitko/transform_processor.py b/src/formatitko/transform_processor.py index 9ed995f..f4257ca 100644 --- a/src/formatitko/transform_processor.py +++ b/src/formatitko/transform_processor.py @@ -14,7 +14,7 @@ import importlib import json from .whitespace import NBSP -from .elements import FQuoted +from .elements import FQuoted, Slanted from .context import Group, InlineGroup, BlockGroup from .util import nullify, import_md from .context import Context, CommandCallable @@ -262,6 +262,12 @@ class TransformProcessor(NOPProcessor): raise TypeError(f"Cannot print value of metadatum '{e.content[0].text[1:]}' of type '{type(val)}'") return e + if "slanted" in e.classes: + # `.slanted` class for Span + # Content of Span is enclosed into Slanted (subclass os Emph) + return self.transform(Slanted(*e.content)) + + return e def transform_CodeBlock(self, e: CodeBlock) -> Union[CodeBlock, Div, Null]: