From a178477195f19a1fef5463a8bd2e38f04305498e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Fri, 21 Apr 2023 17:14:42 +0200 Subject: [PATCH] conditional sections --- spip2md/metadata.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spip2md/metadata.py b/spip2md/metadata.py index 8493c84..4338bfc 100644 --- a/spip2md/metadata.py +++ b/spip2md/metadata.py @@ -51,10 +51,18 @@ class metadata: # Contains things before the article like caption & titles def get_starting(self): - return "{}\n\n# {}\n".format(self.caption, self.title) + return ( + f"{self.caption}\n" if len(self.caption) > 0 else "" + f"# {self.title}\n" + ) # Contains things after the article like ps & extra def get_ending(self): - return "# EXTRA\n\n{}\n\n# POST-SCRIPTUM\n\n{}\n\n# MICROBLOGGING\n\n{}".format( - self.extra, self.ps, self.microblog + return ( + f"# EXTRA\n\n{self.extra}" + if self.extra != None and len(self.extra) > 0 + else "" + f"# POST-SCRIPTUM\n\n{self.ps}" + if len(self.ps) > 0 + else "" + f"# MICROBLOGGING\n\n{self.microblog}" + if len(self.microblog) > 0 + else "" )