html {
head { title { text "Title" } };
body {
p { class_ "warning"; text "paragraph" }
}
};
####
html {
head { title {} "Title" };
body {
p { class_ "warning" } "paragraph"
}
};
##
##
sub _elem {
my ($elem_name, $content_fn, $text) = @_; #! added $text arg
# an element is represented by the triple [name, attrs, children]
my $elem = [$elem_name, undef, undef];
do { local $__frag = $elem;
$content_fn->();
text($text) if defined $text; #! new line
};
push @{$__frag->[2]}, $elem;
}
sub define_vocabulary {
my ($elems, $attrs) = @_;
eval "sub $_(&@) { _elem('$_',\@_) }" for @$elems; #! proto
eval "sub ${_}_(\$) { _attr('$_',\@_) }" for @$attrs;
}