add sections links regex

This commit is contained in:
Guilhem Fauré 2023-05-30 17:51:44 +02:00
parent fbad1f9563
commit 765b5e93ea
2 changed files with 7 additions and 3 deletions

View File

@ -150,10 +150,14 @@ ARTICLE_LINK = (
) # Name and path can be further replaced with .format()
SECTION_LINK = (
( # SPIP style documents & embeds links
( # SPIP style sections embeds
compile(r"<()(?:rub|rubrique)([0-9]+)(?:\|(.*?))?>", S | I),
r"[{}]({})",
),
( # SPIP style sections links
compile(r"\[ *([^\]]*?) *-> *(?:rub|rubrique)([0-9]+) *\]", S | I),
r"[{}]({})",
),
( # Markdown style internal links
compile(r"\[(.*?)\]\((?:rub|rubrique)([0-9]+)(?:\|(.*?))?\)", S | I),
r"[{}]({})",

View File

@ -232,7 +232,7 @@ class SpipObject(SpipWritable):
repl: str = path_link.format(match.group(1), doc.filename())
else:
repl: str = path_link.format(doc.titre, doc.filename())
logging.warn(f"Translating link to {repl}")
logging.info(f"Translating link to {repl}")
return text.replace(match.group(), repl)
def not_found_warn(path_link: str, text: str, match: Match) -> str:
@ -242,7 +242,7 @@ class SpipObject(SpipWritable):
for id_link, path_link in DOCUMENT_LINK:
# print(f"Looking for links like {id_link}")
for match in id_link.finditer(text):
logging.warning(f"Found document link {match.group()} in {self.titre}")
logging.info(f"Found document link {match.group()} in {self.titre}")
try:
doc: Document = Document.get(Document.id_document == match.group(2))
text = found_replace(path_link, doc, text, match)