Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P776
hackmd2rst
Active
Public
Actions
Authored by
zack
on Sep 23 2020, 11:14 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
#!/usr/bin/perl -w
# converts markdown exported from hackmd.io to reStructuredText
# SPDX-FileCopyrightText: © 2020 Stefano Zacchiroli <zack@upsilon.cc>
# 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"
;
}
}
Event Timeline
zack
edited the content of this paste.
(Show Details)
Sep 23 2020, 11:14 PM
2020-09-23 23:14:02 (UTC+2)
zack
changed the title of this paste from untitled to
hackmd2rst
.
zack
updated the paste's language from
autodetect
to
perl
.
Log In to Comment