#!/usr/bin/perl -w # converts markdown exported from hackmd.io to reStructuredText # SPDX-FileCopyrightText: © 2020 Stefano Zacchiroli # SPDX-License-Identifier: GPL-3.0-or-later use strict; my $md_fname = $ARGV[0]; die "Usage: hackmd2rst MARKDOWN_FILE\n" unless defined $md_fname; open(my $rst, "pandoc -f markdown -t rst '$md_fname' |") or die "pandoc conversion failure"; while (my $line = <$rst>) { chomp $line; if ($line =~ /^\s*\[TOC\]\s*$/) { print(".. toctree::\n"); print(" :maxdepth: 2\n"); } elsif ($line =~ /^\s+\[[^\]]+\]\s+(.*)/) { print(".. note::\n\n"); print(" $1\n"); } else { print $line, "\n"; } }