convert_html_md
Summary
Extended version of the Nimbus HTML to Markdown gist.
Uses pandoc to convert HTML files with asset directories exported from Nimbus for use in other vendor-agnostic Markdown readers (cf. UpNote).
Table of Contents
Setup
- Install
Dependencies
pip
comes with python by default and is sufficient to get up and running quickly. asdf
is a wrapper for pyenv
(among other runtimes) and takes care of python versions. poetry
handles dependencies, virtual environments, and packaging.
pip
# activate a new virtual environment python3 -m venv .venv; . .venv/bin/activate; pip3 install --upgrade pip # install dependencies python3 -m pip install -r requirements.txt
asdf
# add python plugin asdf plugin-add python # install stable python asdf install python <latest> # 3.10.8 # uninstall version asdf uninstall python latest # refresh symlinks for installed python runtimes asdf reshim python # set working directory version (i.e., repo) asdf local python latest # set stable to system python asdf global python latest
poetry
# Install curl -sSL https://install.python-poetry.org | $(which python3) - # Uninstall export POETRY_UNINSTALL=1 curl -sSL https://install.python-poetry.org | $(which python3) - # Change config poetry config virtualenvs.in-project true # .venv in `pwd` # Install from requirements.txt poetry add `cat requirements.txt` # Update dependencies poetry update # Remove library poetry remove <lib> # Generate requirements.txt poetry export -f requirements.txt --output requirements.txt --without-hashes
- Poetry with
asdf
# Add poetry asdf plugin asdf plugin-add poetry https://github.com/asdf-community/asdf-poetry.git # Install latest version via asdf asdf install poetry latest # Set latest version as default asdf global poetry latest # Install via asdf w/version ASDF_POETRY_INSTALL_URL=https://install.python-poetry.org asdf install poetry 1.2.2 asdf local poetry 1.2.2
Usage
- Virtual environment
# source virtual environment (venv) from dependencies setup above . .venv/bin/activate # run program from top-level directory python3 convert.py # exit deactivate
- Poetry
# Run script and exit environment poetry run python convert.py # Activate virtual environment (venv) poetry shell # Run script python convert.py # Deactivate venv exit # ctrl-d
TODO
Document usage- Parallelize with
joblib
- Benchmark
- 3.10.8
- 3.11.0
- Pre/post-parallelization
- Open Issues
Further Reading
Convert Nimbus Notes HTML to Markdown for Joplin
Python decorator to measure execution time - DEV Community 👩💻👨💻
The Boilerplate for Logging in Python | by Ezz El Din Abdullah | Brainwave | Medium
Replace multiple spaces with a single space in Python | bobbyhadz
Python's zipfile: Manipulate Your ZIP Files Efficiently – Real Python