#!/usr/bin/perl # normalize Markdown use Getopt::Long; use File::Slurp; use Lingua::Sentence; use strict; use warnings; # setup sentence splitter my $splitter = Lingua::Sentence->new("en"); my $force; GetOptions ("force|f"); my $stem = shift; $_ = read_file( $stem . '.md' ); # join non-headline multi-lines s/([^\n=])\n/$1 /g; #s/(?<=[\S^=])\h*\n(?=[\S^=])/ /g; # split into sentences $_ = $splitter->split($_); # split after comma, and before and after ellipsis #s/,\s(?=[^\v=]*\v)/,\n/mg; s/\h+(\(…\))/\n$1/mg; s/(\(…\))\h+/$1\n/mg; write_file( $stem . '.mdwn', $_ ); print "DONE: $0 stem $stem\n";