diff --git a/pyproject.toml b/pyproject.toml index 7531de4..13197d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ pymysql = "^1.0.3" peewee = "^3.16.2" [tool.poetry.scripts] -spip2md = "spip2md.cli:main" +spip2md = "spip2md:main" [build-system] requires = ["poetry-core"] diff --git a/spip2md/cli.py b/spip2md/__init__.py similarity index 100% rename from spip2md/cli.py rename to spip2md/__init__.py diff --git a/spip2md/__main__.py b/spip2md/__main__.py index 882c03b..dca2f90 100644 --- a/spip2md/__main__.py +++ b/spip2md/__main__.py @@ -1,4 +1,4 @@ # SPIP website to plain Markdown files converter, Copyright (C) 2023 Guilhem Fauré -from spip2md.cli import main +from spip2md import main main() diff --git a/spip2md/converters.py b/spip2md/converters.py index 2dfe090..5222286 100644 --- a/spip2md/converters.py +++ b/spip2md/converters.py @@ -106,13 +106,6 @@ SPIP_TO_MARKDOWN = ( ), "```\n\\1\n\n```", ), - ( # WARNING Keep only the first language in multi-language blocks - compile( - r"\s*(?:\[.{2,4}\])?\s*(.*?)\s*(?:\s*\[.{2,4}\].*)*<\/multi>", - S | I, - ), - r"\1", - ), ( # WARNING remove every html tag compile(r"<\/?.*?>\s*", S | I), r"", @@ -252,6 +245,12 @@ UNKNOWN_ISO = ( r"∆", ) +# Multi language block, capture the first +MULTILINGUAL = compile( + r"\s*(?:\[.{2,4}\])?\s*(.*?)\s*(?:\s*\[.{2,4}\].*)*<\/multi>", + S | I, +) + # Apply SPIP to Markdown & ISO to UTF conversions to a text, & eventually clean meta def convert(text: Optional[str], clean_meta: bool = False) -> str: diff --git a/spip2md/spipobjects.py b/spip2md/spipobjects.py index c6399ba..dc0cb09 100644 --- a/spip2md/spipobjects.py +++ b/spip2md/spipobjects.py @@ -84,7 +84,10 @@ class Document(SpipWritable, SpipDocuments): def filename(self, date: bool = False) -> str: name_type: tuple[str, str] = splitext(basename(str(self.fichier))) return ( - slugify((self.date_publication + "-" if date else "") + name_type[0]) + slugify( + (self.date_publication + "-" if date else "") + name_type[0], + max_length=100, + ) + name_type[1] ) @@ -161,7 +164,7 @@ class SpipObject(SpipWritable): def dir_slug(self, include_date: bool = False, end_slash: bool = True) -> str: date: str = self.date + "-" if include_date else "" slash: str = "/" if end_slash else "" - return slugify(date + self.titre) + slash + return slugify(date + self.titre, max_length=100) + slash # Get filename of this object def filename(self) -> str: