From c41856376141e5f0d5949915f36a9fbaf814af76 Mon Sep 17 00:00:00 2001 From: Remi PLANEL <rplanel@pasteur.fr> Date: Wed, 3 Apr 2024 15:03:06 +0200 Subject: [PATCH] update markdown function to modify articles --- .../df-wiki-cli/df_wiki_cli/content/main.py | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/packages/df-wiki-cli/df_wiki_cli/content/main.py b/packages/df-wiki-cli/df_wiki_cli/content/main.py index 19e39629..086f6db1 100644 --- a/packages/df-wiki-cli/df_wiki_cli/content/main.py +++ b/packages/df-wiki-cli/df_wiki_cli/content/main.py @@ -506,16 +506,46 @@ def markdown( # with open(dst, "w") as tmp_f: dst = Path(tmp_path) dst.write_bytes(file.read_bytes()) + # check if article has ## Structure, ## Experimental Validation, ## Distribution of the system among prokaryotes with open(dst, "r+") as f: - new_f = re.sub( - r"##\s+Structure\n.*##\s+Experimental\s+validation", - "## Structure\n\n::article-structure\n::\n\n## Experimental validation", - f.read(), - flags=re.DOTALL, - ) - with open(file, "w") as f_out: - f_out.write(new_f) + + all_file = f.read() + + if ( + re.search( + r"#{2}\s+Structure", + all_file, + flags=re.IGNORECASE | re.MULTILINE, + ) + and re.search( + r"#{2}\s+Experimental\s+validation", + all_file, + flags=re.IGNORECASE | re.MULTILINE, + ) + and re.search( + r"#{2}\s+Distribution\s+of\s+the\s+system\s+among\s+prokaryotes", + all_file, + flags=re.IGNORECASE | re.MULTILINE, + ) + ): + + new_f_str = re.sub( + r"#{2}\s+Structure.*?#{2}\s+Experimental\s+validation", + "## Structure\n\n### pDockQ matrix\n\n::pdockq-matrix\n::\n\n### List predicted structures\n\n::article-structure\n::\n\n## Experimental validation", + all_file, + flags=re.DOTALL | re.IGNORECASE, + ) + new_f = re.sub( + r"#{2}\s+Distribution\s+of\s+the\s+system\s+among\s+prokaryotes.*?#{2}\s+Structure", + "## Distribution of the system among prokaryotes\n\n::article-system-distribution-plot\n::\n\n## Structure", + new_f_str, + flags=re.DOTALL | re.IGNORECASE, + ) + with open(file, "w") as f_out: + f_out.write(new_f) + else: + console.log(f"[bold red]check it manually") def remove_version(assembly): -- GitLab