Skip to content

Commit

Permalink
Prepare v0.13.1
Browse files Browse the repository at this point in the history
- Provide an abbreviation for the "backticks" argument
(#9, #20, #21, #22).
  • Loading branch information
peter88213 committed Mar 26, 2024
1 parent 8a260f9 commit 51a3dc2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
28 changes: 21 additions & 7 deletions src/zim2obsidian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
'☐': '[ ]',
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit 51a3dc2

Please sign in to comment.