From 51a3dc2de8c03d0608789415a2dceb04928baccb Mon Sep 17 00:00:00 2001 From: peter88213 Date: Tue, 26 Mar 2024 20:33:20 +0100 Subject: [PATCH] Prepare v0.13.1 - Provide an abbreviation for the "backticks" argument (#9, #20, #21, #22). --- README.md | 4 ++-- src/zim2obsidian.py | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4d6d6ef..8bbf6a7 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ Save the file [zim2obsidian.py](https://raw.githubusercontent.com/peter88213/mar ## Usage of the zim2obsidian.py script ``` -zim2obsidian.py [-h] [--backticks] +zim2obsidian.py [-h] [-b] Convert Zim Markdown export to Obsidian options: -h, --help show a help message and exit - --backticks verbatim blocks and inline code are marked with backticks + -b, --backticks verbatim blocks and inline code are marked with backticks ``` diff --git a/src/zim2obsidian.py b/src/zim2obsidian.py index df0d342..ee1c2ad 100644 --- a/src/zim2obsidian.py +++ b/src/zim2obsidian.py @@ -11,13 +11,13 @@ 3. Copy this Python script into the export root directory. 4. Start zim2obsidian.py by double clicking on it or from the console. -usage: zim2obsidian.py [-h] [--backticks] +usage: zim2obsidian.py [-h] [-b] Convert Zim Markdown export to Obsidian options: -h, --help show a help message and exit - --backticks verbatim blocks and inline code are marked with backticks + -b, --backticks verbatim blocks and inline code are marked with backticks Requires Python 3.6+ Copyright (c) 2023 Peter Triesberger @@ -70,6 +70,7 @@ v0.11.6 - Refactor the code. v0.12.0 - Convert "verbatim" lines as exported by Zim. v0.13.0 - Make the "backticks" code conversion an option. +v0.13.1 - Provide an abbreviation for the "backticks" argument. """ import glob @@ -167,11 +168,14 @@ def remove_first_line(): def change_md_style(backticks=False): """Convert Markdown formatting to Obsidian style. + Optional arguments: + backticks: bool -- If True, verbatim blocks and inline code are marked with backticks. + - Replace Setext-style headings with Atx-style headings - Convert rulers. - Convert highlighting. - Convert checkboxes. - - Convert tags. + - Convert tags. """ CHECKBOXES = { '☐': '[ ]', @@ -225,11 +229,13 @@ def convert_md(text): #--- Convert 1st level heading. print(f'- Converting 1st level heading "{previousLine}" ...') previousLine = f'# {previousLine}' + elif line.startswith('-') and line.count('-') == len(line): #--- Convert 2nd level heading. print(f'- Converting 2nd level heading "{previousLine}" ...') previousLine = f'## {previousLine}' + elif line.startswith('*') and line.count('*') == len(line): #--- Convert horizontal ruler. @@ -319,6 +325,11 @@ def reformat_links(): def main(backticks=False): + """Run the converter + + Optional arguments: + backticks: bool -- If True, verbatim blocks and inline code are marked with backticks. + """ print(f'*** Convert Zim export in "{os.getcwd()}" to Obsidian ***\n') if RENAME_PAGES: rename_pages() @@ -335,9 +346,12 @@ def main(backticks=False): import argparse parser = argparse.ArgumentParser( description='Convert Zim Markdown export to Obsidian', - epilog='') - parser.add_argument('--backticks', - action="store_true", - help='verbatim blocks and inline code are marked with backticks') + epilog='' + ) + parser.add_argument( + '-b', '--backticks', + action="store_true", + help='verbatim blocks and inline code are marked with backticks' + ) args = parser.parse_args() main(args.backticks)