Skip to content

Instantly share code, notes, and snippets.

@librasteve
Created June 22, 2024 17:22
Show Gist options
  • Save librasteve/fb00312d1ffc03a5a16598efd5d5bd59 to your computer and use it in GitHub Desktop.
Save librasteve/fb00312d1ffc03a5a16598efd5d5bd59 to your computer and use it in GitHub Desktop.
Raku Markdown
#!/usr/bin/env raku
use MONKEY-SEE-NO-EVAL;
#| takes markdown file and evals all code lines delimited by '```perl6 xxx ```'
sub MAIN(
$filename!, #= '/pathto/example.md'
) {
my @lines = $filename.IO.lines or die 'no file found';
my $toggle = False;
my $code;
for @lines -> $line {
when $line ~~ /^ '```perl6'/ { $toggle = True }
when $line ~~ /^ '```'/ { $toggle = False }
when $toggle { $code ~= "$line\n" }
}
EVAL $code // warn "no code found";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment