diff options
author | Jonas Smedegaard <dr@jones.dk> | 2024-03-29 13:55:38 +0100 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2024-03-29 14:09:25 +0100 |
commit | b1e19a9d8c9019d90f5450b14b536dc448830a9d (patch) | |
tree | 44bffae6a96b7c6c125eae6cc68d9751754c794d | |
parent | a07337ec6c75aa2c193d5e096791ac52e8528dfd (diff) |
rewrite script hedgedoc2quarto as robust perl script
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | bin/hedgedoc2quarto | 77 | ||||
-rwxr-xr-x | bin/hedgedoc2quarto.sh | 7 |
3 files changed, 78 insertions, 9 deletions
@@ -54,8 +54,7 @@ pad-export-code: code/index.qmd pad-export-code-gantt: code/_gantt.qmd hedgedoc export --md mJnfBHZ7Qr2W1Hu-QppL8A $<~ - bin/hedgedoc2quarto.sh < $<~ > $< - rm -f $<~ + bin/hedgedoc2quarto $<~ $< pad-export-use: use/index.qmd hedgedoc export --md aFt_nNkYTQibl0CQrBJhtQ $< diff --git a/bin/hedgedoc2quarto b/bin/hedgedoc2quarto new file mode 100755 index 0000000..21f8158 --- /dev/null +++ b/bin/hedgedoc2quarto @@ -0,0 +1,77 @@ +#!/usr/bin/perl -g + +use v5.36; +use strict; +use utf8; + +=head1 NAME + +hedgedoc2quarto - convert HedgeDoc content to Quarto + +=head1 VERSION + +Version 0.0.1 + +=head1 SYNOPSIS + + hedgedoc2quarto INFILE OUTFILE + + hedgedoc2quarto < INFILE > OUTFILE + +=head1 DESCRIPTION + +B<hedgedoc2quarto> reformats text content +from HedgeDoc- to Quarto-flavored Markdown, +and adapt Mermaid diagram code. + +Both HedgeDoc and Quarto use Markdown, +but different flavors, +and they support different subsets of Mermaid diagram code. + +=cut + +my ( $infile, $outfile, $bogus ) = @ARGV; +die 'Too many arguments: expected INFILE and OUTFILE' if $bogus; +@ARGV = ($infile) if $infile; +my $content = <>; + +$content =~ s/^(?'fence'[``~]{3,})\s*\Kmermaid\n(?'type'gantt)\n(?'code'.*?\n)\k'fence'$/{mermaid}\n%%| fig-width: 100%\n$+{type}\n$+{code}$+{fence}/gsm; + +$content =~ s/^gantt\K$/\ntickInterval 1month/gm; + +if ($outfile) { + open(FH, '>', $outfile) or die $!; + print FH $content; +} else { + print $content; +} + +=encoding UTF-8 + +=head1 AUTHOR + +Jonas Smedegaard C<< <dr@jones.dk> >> + +=head1 COPYRIGHT AND LICENSE + + Copyright © 2024 Jonas Smedegaard + +This program is free software: +you can redistribute it and/or modify it +under the terms of the GNU Affero General Public License +as published by the Free Software Foundation, +either version 3, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; +without even the implied warranty +of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU Affero General Public License for more details. + +You should have received a copy +of the GNU Affero General Public License along with this program. +If not, see <https://www.gnu.org/licenses/>. + +=cut + +1; diff --git a/bin/hedgedoc2quarto.sh b/bin/hedgedoc2quarto.sh deleted file mode 100755 index eac4b33..0000000 --- a/bin/hedgedoc2quarto.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -eu - -perl -gp \ - -e 's/```\Kmermaid/{mermaid}\n%%| fig-width: 100%/g;'\ - -e 's/^gantt$/gantt\ntickInterval 1month/gm;' |