use init instead of cli & temporarily disable <multi> blocks supressing

This commit is contained in:
Guilhem Fauré 2023-05-26 11:13:21 +02:00
parent 8e8fd4aaf8
commit b51ce330ee
5 changed files with 13 additions and 11 deletions

View File

@ -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"]

View File

@ -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()

View File

@ -106,13 +106,6 @@ SPIP_TO_MARKDOWN = (
),
"```\n\\1\n\n```",
),
( # WARNING Keep only the first language in multi-language blocks
compile(
r"<multi>\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"<multi>\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:

View File

@ -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: