Browse Source

Slanted font

jk-bakalarka
Jiří Kalvoda 9 months ago
parent
commit
37c8ec4e2e
  1. 4
      src/formatitko/elements.py
  2. 7
      src/formatitko/nop_processor.py
  3. 6
      src/formatitko/output_generator.py
  4. 5
      src/formatitko/tex_generator.py
  5. 8
      src/formatitko/transform_processor.py

4
src/formatitko/elements.py

@ -1,4 +1,4 @@
from panflute import Quoted from panflute import Quoted, Emph
from .command import Command, InlineCommand, BlockCommand, CodeCommand from .command import Command, InlineCommand, BlockCommand, CodeCommand
@ -14,3 +14,5 @@ class FQuoted(Quoted):
del kwargs["style"] del kwargs["style"]
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
class Slanted(Emph):
pass

7
src/formatitko/nop_processor.py

@ -6,7 +6,7 @@ from panflute import MetaValue
from typing import Union, Callable from typing import Union, Callable
from .whitespace import NBSP from .whitespace import NBSP
from .elements import FQuoted from .elements import FQuoted, Slanted
from .context import Group, InlineGroup, BlockGroup, Context from .context import Group, InlineGroup, BlockGroup, Context
from .whitespace import Whitespace from .whitespace import Whitespace
from .command import BlockCommand, InlineCommand, CodeCommand, Command from .command import BlockCommand, InlineCommand, CodeCommand, Command
@ -69,6 +69,7 @@ class NOPProcessor:
Cite: self.transform_Cite, Cite: self.transform_Cite,
Code: self.transform_Code, Code: self.transform_Code,
Emph: self.transform_Emph, Emph: self.transform_Emph,
Slanted: self.transform_Slanted,
Image: self.transform_Image, Image: self.transform_Image,
LineBreak: self.transform_LineBreak, LineBreak: self.transform_LineBreak,
Link: self.transform_Link, Link: self.transform_Link,
@ -263,6 +264,10 @@ class NOPProcessor:
e.content = self.transform(e.content) e.content = self.transform(e.content)
return e return e
def transform_Slanted(self, e: Slanted) -> Slanted:
e.content = self.transform(e.content)
return e
def transform_Link(self, e: Link) -> Link: def transform_Link(self, e: Link) -> Link:
e.content = self.transform(e.content) e.content = self.transform(e.content)
return e return e

6
src/formatitko/output_generator.py

@ -7,7 +7,7 @@ from panflute import stringify
from typing import Union, Callable from typing import Union, Callable
from .whitespace import NBSP from .whitespace import NBSP
from .elements import FQuoted from .elements import FQuoted, Slanted
from .context import Group, InlineGroup, BlockGroup, Context from .context import Group, InlineGroup, BlockGroup, Context
@ -108,6 +108,7 @@ class OutputGenerator:
Cite: self.generate_Cite, Cite: self.generate_Cite,
Code: self.generate_Code, Code: self.generate_Code,
Emph: self.generate_Emph, Emph: self.generate_Emph,
Slanted: self.generate_Slanted,
Image: self.generate_Image, Image: self.generate_Image,
LineBreak: self.generate_LineBreak, LineBreak: self.generate_LineBreak,
Link: self.generate_Link, Link: self.generate_Link,
@ -376,6 +377,9 @@ class OutputGenerator:
def generate_Emph(self, e: Emph): def generate_Emph(self, e: Emph):
self.generate_simple_tag(e) self.generate_simple_tag(e)
def generate_Slanted(self, e: Slanted):
self.generate_Emph(e)
def generate_Image(self, e: Image): def generate_Image(self, e: Image):
self.generate_simple_tag(e) self.generate_simple_tag(e)

5
src/formatitko/tex_generator.py

@ -179,6 +179,11 @@ class UCWTexGenerator(OutputGenerator):
self._italic-=1 self._italic-=1
self.write(r"}") 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): def generate_Strong(self, e: Strong):
if self._italic > 0: if self._italic > 0:
self.write(r"{\bi{}") self.write(r"{\bi{}")

8
src/formatitko/transform_processor.py

@ -14,7 +14,7 @@ import importlib
import json import json
from .whitespace import NBSP from .whitespace import NBSP
from .elements import FQuoted from .elements import FQuoted, Slanted
from .context import Group, InlineGroup, BlockGroup from .context import Group, InlineGroup, BlockGroup
from .util import nullify, import_md from .util import nullify, import_md
from .context import Context, CommandCallable 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)}'") raise TypeError(f"Cannot print value of metadatum '{e.content[0].text[1:]}' of type '{type(val)}'")
return e 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 return e
def transform_CodeBlock(self, e: CodeBlock) -> Union[CodeBlock, Div, Null]: def transform_CodeBlock(self, e: CodeBlock) -> Union[CodeBlock, Div, Null]:

Loading…
Cancel
Save