summaryrefslogtreecommitdiff
path: root/bin/hedgedoc2quarto
blob: 21f81588616a45eb244bb66a3fd1d544eedfbf00 (plain)
  1. #!/usr/bin/perl -g
  2. use v5.36;
  3. use strict;
  4. use utf8;
  5. =head1 NAME
  6. hedgedoc2quarto - convert HedgeDoc content to Quarto
  7. =head1 VERSION
  8. Version 0.0.1
  9. =head1 SYNOPSIS
  10. hedgedoc2quarto INFILE OUTFILE
  11. hedgedoc2quarto < INFILE > OUTFILE
  12. =head1 DESCRIPTION
  13. B<hedgedoc2quarto> reformats text content
  14. from HedgeDoc- to Quarto-flavored Markdown,
  15. and adapt Mermaid diagram code.
  16. Both HedgeDoc and Quarto use Markdown,
  17. but different flavors,
  18. and they support different subsets of Mermaid diagram code.
  19. =cut
  20. my ( $infile, $outfile, $bogus ) = @ARGV;
  21. die 'Too many arguments: expected INFILE and OUTFILE' if $bogus;
  22. @ARGV = ($infile) if $infile;
  23. my $content = <>;
  24. $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;
  25. $content =~ s/^gantt\K$/\ntickInterval 1month/gm;
  26. if ($outfile) {
  27. open(FH, '>', $outfile) or die $!;
  28. print FH $content;
  29. } else {
  30. print $content;
  31. }
  32. =encoding UTF-8
  33. =head1 AUTHOR
  34. Jonas Smedegaard C<< <dr@jones.dk> >>
  35. =head1 COPYRIGHT AND LICENSE
  36. Copyright © 2024 Jonas Smedegaard
  37. This program is free software:
  38. you can redistribute it and/or modify it
  39. under the terms of the GNU Affero General Public License
  40. as published by the Free Software Foundation,
  41. either version 3, or (at your option) any later version.
  42. This program is distributed in the hope that it will be useful,
  43. but WITHOUT ANY WARRANTY;
  44. without even the implied warranty
  45. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  46. See the GNU Affero General Public License for more details.
  47. You should have received a copy
  48. of the GNU Affero General Public License along with this program.
  49. If not, see <https://www.gnu.org/licenses/>.
  50. =cut
  51. 1;