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 19e396295625fa6c45361d4497b3f9f090a8d1ae..086f6db12475b6727d31107eddfc568a1ef5817c 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):