Functional syntax highlighting for rust
This commit is contained in:
parent
731d7aa19c
commit
19e06488c4
7 changed files with 299 additions and 5 deletions
|
@ -1,9 +1,13 @@
|
|||
use v6.e.PREVIEW;
|
||||
|
||||
use Pandoc;
|
||||
use JSON::Class:auth<zef:vrurg>;
|
||||
use Pygments;
|
||||
use DB::Post;
|
||||
|
||||
|
||||
use JSON::Class:auth<zef:vrurg>;
|
||||
use File::Temp;
|
||||
|
||||
#| A plain markdown post
|
||||
unit class MarkdownPost does Post is json(:pretty);
|
||||
|
||||
|
@ -20,7 +24,17 @@ method title(--> Str:D) {
|
|||
|
||||
# Simply provide our source file to pandoc
|
||||
method render-html(--> Str:D) {
|
||||
markdown-to-html $!source
|
||||
# Test to see if this posts contains any fenced code blocks, if so,
|
||||
# pygmentize it through a temporary file
|
||||
my $contents = $!source.slurp;
|
||||
if $contents ~~ /'```'/ {
|
||||
my $output = highlight-code $contents;
|
||||
my ($filename, $filehandle) = tempfile;
|
||||
$filehandle.spurt: $output, :close;
|
||||
markdown-to-html $filename.IO
|
||||
} else {
|
||||
markdown-to-html $!source
|
||||
}
|
||||
}
|
||||
|
||||
# Return our summary, if we have one, otherwise extract the first paragraph of
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue