From 23314d8a53abeb677ecc5cd65e026fe6792c758f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Mon, 8 Jan 2024 14:08:32 -0500 Subject: [PATCH] ajustement fonctionnement --- .../markdown_fix_freeplane.py | 17 ++++++++++++----- markdown_fix_freeplane/markdown_utils.py | 6 ++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/markdown_fix_freeplane/markdown_fix_freeplane.py b/markdown_fix_freeplane/markdown_fix_freeplane.py index b6edba5..cf208b1 100644 --- a/markdown_fix_freeplane/markdown_fix_freeplane.py +++ b/markdown_fix_freeplane/markdown_fix_freeplane.py @@ -7,16 +7,15 @@ License: Copyright (c) 2024 François Pelletier """ - import sys -from markdown_fix_freeplane.markdown_utils import replace_title_with_list +from markdown_utils import replace_title_with_list # %% main function -def __main__(): +def main(): """Run the script. Args: @@ -27,11 +26,19 @@ def __main__(): --- Examples: - >>> __main__() + >>> main() --- """ + if len(sys.argv) < 2: + print("Usage: python markdown_to_list.py ") + sys.exit(1) # read file passed as argument with open(sys.argv[1], 'r') as my_file: text = my_file.read() - return replace_title_with_list(text) + print(replace_title_with_list(text)) + + +if __name__ == '__main__': + main() + diff --git a/markdown_fix_freeplane/markdown_utils.py b/markdown_fix_freeplane/markdown_utils.py index 3c57281..8054f0c 100644 --- a/markdown_fix_freeplane/markdown_utils.py +++ b/markdown_fix_freeplane/markdown_utils.py @@ -36,6 +36,8 @@ def replace_title_with_list(text: str) -> str: pattern = r'^#+' matches = re.findall(pattern, text, re.MULTILINE) for match in matches: - nb_hashtag = len(match)-1 - text = re.sub(match, ' ' * nb_hashtag+'-', text, count=1) + nb_hashtag = len(match) + if nb_hashtag > 1: + text = re.sub(match, ' ' * (nb_hashtag-1)+'-', text, count=1) + text = re.sub('\n\n', '\n', text) return text