configuration de tests et de création de package
This commit is contained in:
parent
75f7a2d742
commit
d10a51757b
12 changed files with 173 additions and 19 deletions
9
markdown_fix_freeplane/__init__.py
Normal file
9
markdown_fix_freeplane/__init__.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
"""Convert Freeplane generated markdown.
|
||||
|
||||
License:
|
||||
MIT License
|
||||
Copyright (c) 2024 François Pelletier
|
||||
"""
|
||||
|
||||
__version__ = '0.0.1'
|
||||
__author__ = 'François Pelletier'
|
37
markdown_fix_freeplane/markdown_fix_freeplane.py
Normal file
37
markdown_fix_freeplane/markdown_fix_freeplane.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""Include main function to convert Freeplane generated markdown.
|
||||
|
||||
License:
|
||||
MIT License
|
||||
Copyright (c) 2024 François Pelletier
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
from markdown_fix_freeplane.markdown_utils import replace_title_with_list
|
||||
|
||||
|
||||
# %% main function
|
||||
|
||||
|
||||
def __main__():
|
||||
"""Run the script.
|
||||
|
||||
Args:
|
||||
sys.argv (list): list of command line arguments passed to the script.
|
||||
|
||||
Returns:
|
||||
str: the processed Markdown text.
|
||||
---
|
||||
|
||||
Examples:
|
||||
>>> __main__()
|
||||
---
|
||||
|
||||
"""
|
||||
# read file passed as argument
|
||||
with open(sys.argv[1], 'r') as my_file:
|
||||
text = my_file.read()
|
||||
return replace_title_with_list(text)
|
41
markdown_fix_freeplane/markdown_utils.py
Normal file
41
markdown_fix_freeplane/markdown_utils.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
"""Include functions to work with markdown text.
|
||||
|
||||
License:
|
||||
MIT License
|
||||
Copyright (c) 2024 François Pelletier
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def replace_title_with_list(text: str) -> str:
|
||||
r"""Replace all titles in the text with a numbered list.
|
||||
|
||||
The titles are defined by a hashtag symbol followed by one or more
|
||||
hashtag symbols, followed by a space, and then the title text.
|
||||
The function replaces the entire hashtag symbol and space with a
|
||||
numbered list, where each item in the list is numbered with a
|
||||
hashtag symbol and a space, and the title text is listed after the
|
||||
number.
|
||||
|
||||
Args:
|
||||
text (str): The text to process.
|
||||
|
||||
Returns:
|
||||
str: The processed text.
|
||||
---
|
||||
|
||||
Examples:
|
||||
>>> replace_title_with_list("# This is a title")
|
||||
'- This is a title'
|
||||
>>> replace_title_with_list("# This is a title\n## Another title")
|
||||
'- This is a title\n - Another title'
|
||||
---
|
||||
|
||||
"""
|
||||
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)
|
||||
return text
|
Loading…
Add table
Add a link
Reference in a new issue