dg-x/lib/Classy/Handler/Fragment.pm
snow flurry fb0d94a2c0 Add Markdent GFM extensions
- Per-image classes, to restrict what images a CSS selector acts on
  (in-post vs out-of-post)
- Fenced aside blocks (`!!!`-enclosed, like code blocks)
- Footnotes are handled by the Markdown parser, instead of manually
2024-10-05 17:24:16 -07:00

65 lines
1.3 KiB
Perl

package Classy::Handler::Fragment;
use strict;
use warnings;
use namespace::autoclean;
our $VERSION = '0.10';
use Markdent::Role::HTMLStream;
use List::Util qw(first);
use Classy::Event::AsideBlock;
use Markdent::Types;
use Params::ValidationCompiler qw( validation_for );
use Moose;
with 'Markdent::Role::HTMLStream';
# We're a fragment, don't output start/end document
sub start_document { }
sub end_document { }
around '_stream_start_tag' => sub {
my $orig = shift;
my $self = shift;
my $tag = shift;
my $attr = shift;
if ($tag eq "img" && !exists $attr->{class}) {
$attr->{class} = "as-post";
}
$self->$orig($tag, $attr);
};
{
my $validator = validation_for(
params => [
inner => { type => t('Str') },
class => {
type => t('Str'),
optional => 1,
},
],
named_to_list => 1,
);
sub aside_block {
my $self = shift;
my ( $inner, $class ) = $validator->(@_);
my %attrs = ( class => "aside" );
if ( $class ) {
$attrs{class} .= " $class";
}
$self->_stream_start_tag( 'div', \%attrs );
$self->_stream_text($inner);
$self->_stream_end_tag('div');
}
}
1;