Skip to content

Instantly share code, notes, and snippets.

@STrRedWolf
Created September 16, 2024 15:03
Show Gist options
  • Save STrRedWolf/036f059c36c8bb7b7412c43880d435f0 to your computer and use it in GitHub Desktop.
Save STrRedWolf/036f059c36c8bb7b7412c43880d435f0 to your computer and use it in GitHub Desktop.
Fiction writing using Markdown
#!/usr/bin/perl
use strict;
use File::Basename;
if(scalar @ARGV < 1 || @ARGV > 2) {
print STDERR "Argument count mismatch\n";
exit 1;
}
my $in=$ARGV[0];
my $orig=basename($in);
my $base=basename($in,".md");
my $cr="custom-ref.docx";
$cr=$ARGV[1] if(@ARGV == 2);
open(IN,"<",$in) || die "Can't open $in: $!";
open(OUT,"|-","pandoc","-s","--reference-doc=custom-ref.docx",
"-f","markdown+bracketed_spans+backtick_code_blocks+fenced_code_attributes+fenced_divs",
"--wrap=preserve","-t","docx","-o","$base.docx") || die "Can't output to pandoc: $!";
while(<IN>) {
chomp;
my $l=$_;
$l=~s/\[(.+?)\]{\.Rose}/\[\\\[$1\\\]\]{\.Rose}/g;
$l=~s/\]{\.(\S+?)}/\]{custom-style="$1"}/g;
print OUT "$l \n";
}
close(IN);
close(OUT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment