Background story

I love simplicity of writing text. It's simple and fast.

When coming to this tilde space, I quickly realized that there is no pandoc, no hugo, and probably no other document converter or static site management installed on this system. So I quickly thought how to do web development with no markdown to html converter available?

Then, I found that python3 is available here. With vast number of packages, python3 is of course a natural choice for beginner like me.

Roadblock: still new to python

After some days, I read online course about python so I can grasp the basic. Fortunately, it did not take a long time to understand the basics, since the available courses are so easy to understand.

My points of learning python are as follows.

First attempt

I wrote a markdown to html with template and metadata support using markdown package.

First, I set up a python virtual environment to install packages from pypi.

python3 -m venv --upgrade-deps ~/.local/pyvenv

Then I sourced the ~/.local/pyvenv/bin/activate to activate the virtual environment inside my shell.

. ~/.local/pyvenv/bin/activate

To make it easy to source the activate shell script, I add this function to my ~/.bash_aliases

activate_pyvenv()
{
. ~/.local/pyvenv/bin/activate
}

From the activated environment, I can install markdown package from pypi to work with markdown text sources.

pip install markdown

Working prototype

Ok, finally got a working prototype.

If you are curious, get the source via git. Update: you can view the repository page here.

git clone https://tilde.guru/~mydeardiary/project/python-webspace.git

There will be a single file main.py in the workspace, which will read stdin as markdown text and printing html document to stdout. So the usage will be as follow.

python3 ./main.py < input.md > output.html

Feel free to suggest improvements. Drop an email to mydeardiary (at) tilde.guru.

Support mydeardiary on Ko-Fi

Back to homepage