summaryrefslogtreecommitdiff
path: root/mkmd2mdwn-default
blob: 7e9fd9cd54768e75be32369dfda38419f575d8b4 (plain)
  1. #!/usr/bin/perl
  2. # normalize Markdown
  3. use Getopt::Long;
  4. use File::Slurp;
  5. use Lingua::Sentence;
  6. use strict;
  7. use warnings;
  8. use charnames ':full';
  9. # setup sentence splitter
  10. my $splitter = Lingua::Sentence->new("en");
  11. my $force;
  12. GetOptions ("force|f");
  13. my $stem = shift;
  14. $_ = read_file( $stem . '.md' );
  15. # join non-headline multi-lines
  16. s/([^\n=])\n/$1 /g;
  17. #s/(?<=[\S^=])\h*\n(?=[\S^=])/ /g;
  18. # split into sentences
  19. $_ = $splitter->split($_);
  20. # split after comma, and before and after ellipsis
  21. #s/,\s(?=[^\v=]*\v)/,\n/mg;
  22. s/\h+(\(\N{HORIZONTAL ELLIPSIS}\))/\n$1/mg;
  23. s/(\(\N{HORIZONTAL ELLIPSIS}\))\h+/$1\n/mg;
  24. write_file( $stem . '.mdwn', $_ );
  25. print "DONE: $0 stem $stem\n";