Giter VIP home page Giter VIP logo

zettel-link-rewriter's Introduction

Rewrite Wikilinks in your Zettelkasten as Markdown Links

This repository contains a Python script that can take a folder of Markdown files (or any other compatible format) and convert any links that are in [[wikilink]] format into the standard Markdown link format.

Why?

Most Zettelkasten software today will handle linking between different notes by adding a link using the [[wikilink]] syntax. This is great for reading and writing within the Zettelkasten ecosystem but almost no standard Markdown renderer will automatically recognize the [[wikilink]] syntax. This script attempts to give you more inter-operability with other Markdown software by converting [[wikilinks]] into standard Markdown [wikilink](wikilink) syntax.

Features

  • Fully cross-platform. Script was developed in a Windows environment and is extensively tested to work in Windows.
  • Provides a number of parameters to configure the script. Parameters can be specified either on the command-line or via a configuration file. Refer to zettel_link_rewriter.ini to see an example.
  • Handles links within Markdown code blocks correctly, i.e., does not rewrite them. This includes fenced code blocks, inline code snippets and code blocks indented with four spaces. Do note the Caveats though.
  • Minimal dependencies. The script requires only one additional package to be installed (which is because Python's built-in argparse module is terrible.)

Dependencies

  • Python 3.4 or higher (Script has only been tested with Python 3.8)
  • List of packages specified in requirements.txt

Getting Started

You can use this script by cloning the repo and installing Python and the script dependencies in a Python venv.

git clone https://github.com/balaji-dutt/zettel-link-rewriter.git
python -m venv .venv
./venv/scripts/activate
pip install -r requirements.txt
python zettel_link_rewriter.py

Running the script as shown above will make the script run with a set of built-in defaults. But you can configure the script either by supplying a list of parameters on the command-line:

python zettel_link_rewriter.py -v debug -p all --target_files ./dest/

Or you can configure the script by passing a path to a configuration file:

python zettel_link_rewriter.py -c myconfig.ini

An explanation of the different parameters the script recognizes are provided below.

Parameters

Parameter Mandatory Description
-h No Show a help message
-c / --config No Specify path to Configuration file.
By default, the script will look for a configuration file named zettel_link_rewriter.ini in the same directory
-v No Verbosity option. Configures the logging level for the script. You can specify 3 levels of verbosity - warning/info/debug. The default is warning
-f / --file No Write log messages to a file instead of on the console.
--source_files No Specify path to directory containing source markdown files to be processed.
Default is to use a "source" folder in the current directory.
--target_files No Specify path to directory where processed markdown files should be saved.
Default is to use a "dest" folder in the current directory.
The folder where markdown files should be saved after processing will be created if it does not exist.
-p / --process No Flag to tell the script whether it should process all files in the source directory or only receently modified files.
The parameter supports two values - all or modified
-m / --minutes No Specify in minutes the time-limit for finding recently modified files. Can be used with -p modified option.
If this is not specified, the script will use a default value of 60 minutes.

Caveats

  • In order to avoid processing wikilinks inside code blocks, the script will ignore lines beginning with 4 spaces. However, this means that a wikilink in a list that is on the 3rd level or deeper will not be converted. In other words:
- [[Level 1 wikilink]] # Will be converted
  - [[Level 2 wikilink]] # Will be converted
    - [[Level 3 wikilink]] # Will *NOT BE* converted
      - Any wikilinks in this level or deeper will also not be converted. 

zettel-link-rewriter's People

Contributors

balaji-dutt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

zettel-link-rewriter's Issues

add a tests file to document and demonstrate a few conversions?

This looks great! Glancing at the code, I saw that you parse the input document line-by-line based on Regex at some point, and the script is fairly long (longer than a simple global String replacement! :)), so I guess it contains a couple of syntax checks. That'd be great.

My suggestion is to add a tests file, or maybe even embed the tests if the script is launched without any arguments or a --run-tests flag, or something. I first saw this in http://alanwsmith.com/embedding-a-test-suite-in-a-single-file-ruby-app-part-1 and found that to be a neat pattern for simple CLI scripts where I don't want to create a directory with the script and the tests separately, but still want to document how it behaves.

Anyway, I'd be mostly interested in seeing how

foo `[[bar]` baz 

is handled, and GitHub Flavored Markdown fenced code blocks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.