summaryrefslogtreecommitdiff
path: root/bin/hedgedoc2quarto
blob: 23832ea74f7923cc9aea5ee4d4d8857ece0a1df1 (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
  25. =~ s/^(?'fence'[``~]{3,})\s*\Kmermaid\n(?'type'gantt)\n(?'code'.*?\n)\k'fence'$/
  26. "{mermaid}\n\%\%| fig-width: 100\%\n"
  27. . &mmd2mmd( $+{type}, $+{code} )
  28. . $+{fence}
  29. /gsme;
  30. if ($outfile) {
  31. open( FH, '>', $outfile ) or die $!;
  32. print FH $content;
  33. }
  34. else {
  35. print $content;
  36. }
  37. sub mmd2mmd ( $type, $code )
  38. {
  39. if ( $type eq 'gantt' ) {
  40. $code = "tickInterval 1month\n$code";
  41. }
  42. return "$type\n$code";
  43. }
  44. =encoding UTF-8
  45. =head1 AUTHOR
  46. Jonas Smedegaard C<< <dr@jones.dk> >>
  47. =head1 COPYRIGHT AND LICENSE
  48. Copyright © 2024 Jonas Smedegaard
  49. This program is free software:
  50. you can redistribute it and/or modify it
  51. under the terms of the GNU Affero General Public License
  52. as published by the Free Software Foundation,
  53. either version 3, or (at your option) any later version.
  54. This program is distributed in the hope that it will be useful,
  55. but WITHOUT ANY WARRANTY;
  56. without even the implied warranty
  57. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  58. See the GNU Affero General Public License for more details.
  59. You should have received a copy
  60. of the GNU Affero General Public License along with this program.
  61. If not, see <https://www.gnu.org/licenses/>.
  62. =cut
  63. 1;