App-unbelievable
view release on metacpan or search on metacpan
lib/App/unbelievable.pm view on Meta::CPAN
push @errors, "Could not read JSON: $@" if $@;
push @errors, "No JSON found" unless $charcount;
return ($frontmatter, $markdown) unless(@errors);
# Mainline case: YAML frontmatter with `---` separators
eval {
$reader = Text::FrontMatter::YAML->new(
document_string => $text
);
$frontmatter = $reader->frontmatter_hashref;
$markdown = $reader->data_text // '';
};
push @errors, "Could not read YAML-frontmatter document: $@" if $@;
return ($frontmatter, $markdown) unless @errors;
# Default: assume the full contents are markdown, and there is
# no frontmatter.
_diag(join "\n ", "Assuming plain Markdown $fn --- errors were:", @errors);
return ({}, $text);
} #_load()
# Normalize a syntax name into a key for %SYNTAXES
sub _normalize_syntax {
my $retval = lc(shift);
$retval =~ s/[^A-Za-z0-9]/_/g;
$retval =~ tr/_/_/s;
return $retval;
}
# Populates %SYNTAXES. Must be called before
# _produce_output(). Called by unbelievable().
sub _initialize {
foreach(keys %INC) {
next unless m{Syntax/Highlight/Engine/Kate/([^\.]+).pm$};
$SYNTAXES{_normalize_syntax($1)} = $1;
}
say "Syntaxes:\n", Dumper(\%SYNTAXES) if $VERBOSE >= 2;
} #_initialize()
# Syntax-highlight text
sub _highlight {
my ($lang, $text) = @_;
# Make the highlighter
my $hl = Syntax::Highlight::Engine::Kate->new(
language => $SYNTAXES{$lang},
substitutions => {
"<" => "<",
">" => ">",
"&" => "&",
" " => " ",
"\t" => " ",
"\n" => "<BR>\n",
},
format_table => {
Alert => [ "<font color=\"#0000ff\">", "</font>" ],
BaseN => [ "<font color=\"#007f00\">", "</font>" ],
BString => [ "<font color=\"#c9a7ff\">", "</font>" ],
Char => [ "<font color=\"#ff00ff\">", "</font>" ],
Comment => [ "<font color=\"#7f7f7f\"><i>", "</i></font>" ],
DataType => [ "<font color=\"#0000ff\">", "</font>" ],
DecVal => [ "<font color=\"#00007f\">", "</font>" ],
Error => [ "<font color=\"#ff0000\"><b><i>", "</i></b></font>" ],
Float => [ "<font color=\"#00007f\">", "</font>" ],
Function => [ "<font color=\"#007f00\">", "</font>" ],
IString => [ "<font color=\"#ff0000\">", "" ],
Keyword => [ "<b>", "</b>" ],
Normal => [ "", "" ],
Operator => [ "<font color=\"#ffa500\">", "</font>" ],
Others => [ "<font color=\"#b03060\">", "</font>" ],
RegionMarker => [ "<font color=\"#96b9ff\"><i>", "</i></font>" ],
Reserved => [ "<font color=\"#9b30ff\"><b>", "</b></font>" ],
String => [ "<font color=\"#ff0000\">", "</font>" ],
Variable => [ "<font color=\"#0000ff\"><b>", "</b></font>" ],
Warning => [ "<font color=\"#0000ff\"><b><i>", "</b></i></font>" ],
},
);
return '<div>' . $hl->highlightText($text) . '</div>';
} #_make_highlighter()
# }}}1
1;
__END__
# Rest of the docs {{{1
=head1 FEATURES
=head2 Markdown rendering
All non-hidden files in C<content/> are rendered as Markdown files.
Hidden files are those that start with a C<.> (the Unix convention).
=head2 Fenced code blocks
Fenced code blocks are syntax-highlighted using
L<Syntax::Highlight::Engine::Kate>. Language names are the lowercased
versions of the module suffixes in
L<Syntax::Highlight::Engine::Kate::All|https://metacpan.org/source/MANWAR/Syntax-Highlight-Engine-Kate-0.14/lib/Syntax/Highlight/Engine/Kate/All.pm>.
=head2 Shortcodes
In Markdown inputs, shortcode tags of the form:
{{< KEY [args] >}}
are replaced with the Dancer2 template C<shortcodes/KEY>
(e.g., C<views/shortcodes/foo.tt>). Currently, only one argument is supported;
it is passed to the template as variable C<_0>.
=head2 Templates
Use whatever you want in your routes! Use regular Dancer2 templating.
=head2 Static files
Everything in C<public/> is available under C</>, just as in Dancer2.
=head1 WHY?
Yet another site generator --- can you believe it? And now you know where
the package name comes from ;) .
This package's roadmap is feature parity with L<Hugo|https://gohugo.io/>.
My motivation for writing unbelievable was two-fold:
=over
=item 1.
Perl.com is currently using Hugo, which is not written in Perl!
=item 2.
( run in 1.498 second using v1.01-cache-2.11-cpan-5735350b133 )