From aef47c77c50b11893f7273e585630334ac15f276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Mon, 12 Jun 2023 11:31:16 +0200 Subject: [PATCH] minor fixes --- spip2md/extended_models.py | 14 +++++++------- spip2md/regexmaps.py | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spip2md/extended_models.py b/spip2md/extended_models.py index 178882e..d6dbb7e 100644 --- a/spip2md/extended_models.py +++ b/spip2md/extended_models.py @@ -20,7 +20,7 @@ from spip2md.config import CFG from spip2md.regexmaps import ( ARTICLE_LINK, BLOAT, - CONFIGLANGS, + CONFIG_LANGS, DOCUMENT_LINK, HTMLTAGS, IMAGE_LINK, @@ -134,7 +134,7 @@ class WritableObject(SpipInterface): text = old.sub("", text) else: for old in mapping: - text = old.replace("", text) + text = text.replace(old, "") return text # Warn about unknown chars & replace them with config defined replacement @@ -345,12 +345,12 @@ class RedactionalObject(WritableObject): _text: str # Get rid of other lang than forced in text and modify lang to forced if found - def translate_field(self, forced_lang: str, text: str) -> str: + def translate_multi(self, forced_lang: str, text: str) -> str: LOG.debug(f"Translating blocks of `{self._title}`") # for each blocks, keep only forced lang lang: Optional[Match[str]] = None for block in MULTILANG_BLOCK.finditer(text): - lang = CONFIGLANGS[forced_lang].search(block.group(1)) + lang = CONFIG_LANGS[forced_lang].search(block.group(1)) if lang is not None: # Log the translation trans: str = lang.group(1)[:50].strip() @@ -499,11 +499,11 @@ class RedactionalObject(WritableObject): self._title = self.titre.strip() # Keep storage language title to store it if CFG.storage_language is not None and CFG.storage_language != forced_lang: - self._storage_title = self.translate_field( + self._storage_title = self.translate_multi( CFG.storage_language, self._title ) self._storage_title = self.convert_field(self._storage_title) - self._title = self.translate_field(forced_lang, self._title) + self._title = self.translate_multi(forced_lang, self._title) LOG.debug(f"Convert internal links of {self.lang} `{self._title}` title") self._title = self.replace_links(self._title) LOG.debug(f"Apply conversions to {self.lang} `{self._title}` title") @@ -522,7 +522,7 @@ class RedactionalObject(WritableObject): LOG.debug(f"{type(self).__name__} {self._title} text is empty") self._text = "" return - self._text = self.translate_field(forced_lang, self.texte.strip()) + self._text = self.translate_multi(forced_lang, self.texte.strip()) LOG.debug(f"Convert internal links of {self.lang} `{self._title}` text") self._text = self.replace_links(self._text) LOG.debug(f"Apply conversions to {self.lang} `{self._title}` text") diff --git a/spip2md/regexmaps.py b/spip2md/regexmaps.py index 36e9499..bd2d32d 100644 --- a/spip2md/regexmaps.py +++ b/spip2md/regexmaps.py @@ -13,11 +13,11 @@ SPIP_MARKDOWN = ( ), ( # line break compile(r"\r?\n_ *(?=\r?\n)|
", I), - "\n", # WARNING not the real translation + "\n", # WARNING May not be the real translation ), ( # heading compile(r"\r?\n?\r?\n?\{\{\{ *(.*?) *\}\}\}\r?\n?\r?\n?", S | I), - "\n\n## \\1\n\n", # Translate SPIP headings to h2 + "\n\n## \\1\n\n", # Translate headings to h2 ), ( # strong compile(r"\{\{ *(.*?) *\}\} ?", S | I), @@ -151,13 +151,13 @@ IMAGE_REPL = r"![{}]({})" # Name and path can be further replaced with .format( # Multi language block, to be further processed per lang MULTILANG_BLOCK = compile(r"(.+?)<\/multi>", S | I) -MULTILANGS = compile( # Matches agains all langs of multi blocks - r"\[([a-zA-Z\-]{2,6})\]\s*(.+?)\s*(?=\[[a-zA-Z\-]{2,6}\]|$)", S | I -) -CONFIGLANGS = { # lang of configuration: (match against this lang) +CONFIG_LANGS = { # lang of configuration: (match against this lang) lang: compile(r"\[ *" + lang + r" *\]\s*(.+?)\s*(?=\[[a-zA-Z\-]{2,6}\]|$)", S | I) for lang in CFG.export_languages } +# MULTILANGS = compile( # Matches agains all langs of multi blocks +# r"\[([a-zA-Z\-]{2,6})\]\s*(.+?)\s*(?=\[[a-zA-Z\-]{2,6}\]|$)", S | I +# ) # WARNING probably useless text in metadata fields, to be removed BLOAT = (