blob: c0bde3b429aac22743ff465de7e8f90030d126b3 (
plain)
- #!/usr/bin/perl
- 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 adapts embedded diagram code.
- Both HedgeDoc and Quarto uses Markdown,
- but different flavors,
- and they handle different subsets of Mermaid diagrams.
- =cut
- # slurp INFILE if passed as first argument, or else STDIN
- my ( $infile, $outfile, $bogus ) = @ARGV;
- die 'Too many arguments: expected INFILE and OUTFILE' if $bogus;
- @ARGV = ($infile) if $infile;
- my $content = do { local $/ = undef; <> };
- $content =~ s/^
- (?'fence'[``~]{3,})\s*
- \Kmermaid\n
- (?'type'gantt)\n
- (?'code'.*?\n)
- \k'fence'
- $/
- "{mermaid}\n\%\%| fig-width: 100\%\n"
- . &mmd2mmd( $+{type}, $+{code} )
- . $+{fence}
- /gsmex;
- if ($outfile) {
- open( FH, '>', $outfile ) or die $!;
- print FH $content;
- }
- else {
- print $content;
- }
- sub mmd2mmd ( $type, $code )
- {
- # strip special comment marker '%%QUARTO%%'
- $code =~ s/^\s*+\K%%QUARTO%%//gm;
- return "$type\n$code";
- }
- =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;
|