summaryrefslogtreecommitdiff
path: root/bin/hedgedoc2quarto
blob: 6640b267f2d890ed799c0e80235faa99c0250cc3 (plain)
  1. #!/usr/bin/perl
  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 adapts embedded diagram code.
  16. Both HedgeDoc and Quarto uses Markdown,
  17. but different flavors,
  18. and they handle different subsets of Mermaid diagrams.
  19. =cut
  20. # slurp INFILE if passed as first argument, or else STDIN
  21. my ( $infile, $outfile, $bogus ) = @ARGV;
  22. die 'Too many arguments: expected INFILE and OUTFILE' if $bogus;
  23. @ARGV = ($infile) if $infile;
  24. my $content = do { local $/ = undef; <> };
  25. $content
  26. =~ s/^(?'fence'[``~]{3,})\s*\Kmermaid\n(?'type'gantt)\n(?'code'.*?\n)\k'fence'$/
  27. "{mermaid}\n\%\%| fig-width: 100\%\n"
  28. . &mmd2mmd( $+{type}, $+{code} )
  29. . $+{fence}
  30. /gsme;
  31. if ($outfile) {
  32. open( FH, '>', $outfile ) or die $!;
  33. print FH $content;
  34. }
  35. else {
  36. print $content;
  37. }
  38. sub mmd2mmd ( $type, $code )
  39. {
  40. if ( $type eq 'gantt' ) {
  41. $code = "tickInterval 1month\n$code";
  42. }
  43. return "$type\n$code";
  44. }
  45. =encoding UTF-8
  46. =head1 AUTHOR
  47. Jonas Smedegaard C<< <dr@jones.dk> >>
  48. =head1 COPYRIGHT AND LICENSE
  49. Copyright © 2024 Jonas Smedegaard
  50. This program is free software:
  51. you can redistribute it and/or modify it
  52. under the terms of the GNU Affero General Public License
  53. as published by the Free Software Foundation,
  54. either version 3, or (at your option) any later version.
  55. This program is distributed in the hope that it will be useful,
  56. but WITHOUT ANY WARRANTY;
  57. without even the implied warranty
  58. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  59. See the GNU Affero General Public License for more details.
  60. You should have received a copy
  61. of the GNU Affero General Public License along with this program.
  62. If not, see <https://www.gnu.org/licenses/>.
  63. =cut
  64. 1;