package Text::Dokuwiki::Render::HTML;
use strict;
use warnings;
use utf8;
use base 'Text::Dokuwiki::Render';
my $noclose = {
br => 1,
hr => 1,
};
my $display = {
div => 'block',
ul => 'block',
h1 => 'line',
h2 => 'line',
h3 => 'line',
p => 'line',
br => 'block',
};
sub _escape {
my ($text) = @_;
$text =~ s{\\}{\\\\}go;
$text =~ s{"} {\\"}go;
return $text;
}
sub _attrs {
my ($attrs) = @_;
my $text = "";
while (my ($key, $value) = each($attrs)) {
$text .= sprintf ' %s="%s"', $key, _escape($value);
}
return $text;
}
sub default {
my ($self, $tag, $attrs, $content) = @_;
my $c = $noclose->{$tag} // 0;
my $d = $display->{$tag} // 'inline';
my $text = "<$tag" . _attrs($attrs) . ">";
$text .= "\n" if ($d eq 'block');
return $text if ($c);
$text .= $content;
$text .= "\n" if ($d eq 'block');
$text .= "$tag>";
$text .= "\n" if ($d eq 'block' or $d eq 'line');
return $text;
}
1;