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