diff --git a/README.md b/README.md index 6555970..8fcca6e 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,10 @@ For my Japanese Grammar (JPG) project, I have created a style for explanation on ## convert-usage.py -In my Quartz rendering of my markdown data, I want this kind of data to be in a callout. However, it is not possible to combine HTML and Markdown in Obsidian. For that purpose, this script encapsulates it directly in HTML. To make it both compatible in Obsidian and Quartz, and to be still easy to write, it's done with this python script. This is probably super specific and will not be of use for anybody except me! \ No newline at end of file +In my Quartz rendering of my markdown data, I want this kind of data to be in a callout. However, it is not possible to combine HTML and Markdown in Obsidian. For that purpose, this script encapsulates it directly in HTML. To make it both compatible in Obsidian and Quartz, and to be still easy to write, it's done with this python script. This is probably super specific and will not be of use for anybody except me! + +## Usage + +Usage: `python3 convert-usage.py [root folder]` + +Note: Please be careful, this software applies modifications recursively! \ No newline at end of file diff --git a/examples/sample2.md b/examples/sample2.md new file mode 100644 index 0000000..b83db7d --- /dev/null +++ b/examples/sample2.md @@ -0,0 +1,23 @@ +# test file + +## Lorem ipsum + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris massa eros, feugiat eu dapibus nec, fermentum vel ex. Nulla malesuada luctus pretium. Phasellus ac felis ut nisi lacinia malesuada nec vel odio. Donec tincidunt tincidunt lorem vel tempus. Nullam sed efficitur ligula, a porttitor nibh. Praesent justo dui, venenatis ac mi non, laoreet consequat libero. Aenean ut molestie mauris. Proin mattis volutpat ligula eget tincidunt. Fusce ex eros, condimentum consectetur efficitur vitae, euismod at justo. + +**Usage** + +
+
+

item1

+

item2

+

item3

+

item4

+
+

+ final

+
+ +## Callout + +> [!info] Example +> Callout example +> Careful with BS4 encoding some characters \ No newline at end of file diff --git a/program/convert-usage.py b/program/convert-usage.py index dc13c41..6ce66b6 100644 --- a/program/convert-usage.py +++ b/program/convert-usage.py @@ -29,7 +29,9 @@ def write_file(filename, text): ### Replace ### def convert_pattern(text): - text = re.sub(re_usage, '', text, flags=re.MULTILINE) + text, success = re.subn(re_usage, '', text, flags=re.MULTILINE) + if (success == 0): + return text soup = BeautifulSoup(text, features="html.parser") @@ -40,7 +42,7 @@ def convert_pattern(text): calloutTitle = BeautifulSoup(callout_title_html, features="html.parser") tag.insert_before(calloutTitle) - return str(soup) + return (soup.decode(False, formatter=None)) ### Execution ###