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