From 6e4683716eade6a7254921dc17d7fb5868a5423c Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 31 May 2023 02:58:49 +0800 Subject: Pass params through fields --- main.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 895b2c0..dcf7e58 100644 --- a/main.py +++ b/main.py @@ -113,11 +113,13 @@ def tokenize(lyric: Tag) -> typing.Iterator[Token]: class LatexGenerator: centering: bool cjk: CJKProvider + artist: typing.Optional[str] + title: typing.Optional[str] def __init__(self): - pass + self.artist, self.title = None, None - def generate_lyric(self, lyric_tokens: typing.Iterator[Token], artist=None, title=None) -> str: + def generate_lyric(self, lyric_tokens: typing.Iterator[Token]) -> str: injectors = [] injectors.append(LatexDocInjectionInfo([], [r'\usepackage{pxrubrica}'], [])) injectors.append(LatexDocInjectionInfo([], [r'\usepackage{setspace}', r'\doublespacing'], [])) @@ -131,8 +133,8 @@ class LatexGenerator: r'\setCJKmonofont{Noto Sans Mono CJK TC}', ], [])) injectors.append(LatexDocInjectionInfo([], [ - r'\author{%s}' % (artist or ''), - r'\title{%s}' % (title or ''), + r'\author{%s}' % (self.artist or ''), + r'\title{%s}' % (self.title or ''), r'\date{}', ], [])) injectors.append(LatexDocInjectionInfo([], [r'\begin{document}'], [r'\end{document}'])) @@ -194,7 +196,8 @@ def main(): artist = v elif k == 'page_song': title = v - print(gen.generate_lyric(tokens, artist, title)) + gen.artist, gen.title = artist, title + print(gen.generate_lyric(tokens)) if __name__ == '__main__': -- cgit v1.2.3