ajustement fonctionnement
This commit is contained in:
parent
fe8d9f4223
commit
23314d8a53
2 changed files with 16 additions and 7 deletions
|
@ -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 <file>")
|
||||
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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue