App-DocKnot
view release on metacpan or search on metacpan
lib/App/DocKnot/Spin/Text.pm view on Meta::CPAN
$paragraph .= $line;
}
if (defined($line)) {
$paragraph .= $line;
}
while (defined($line = <$in_fh>) && $line =~ m{ \A \s* \z }xms) {
$paragraph .= $line;
}
$self->_buffer_line($line);
return $paragraph;
}
# Read from the input file descriptor, skipping blank lines.
sub _skip_blank_lines {
my ($self) = @_;
my $line;
do {
$line = $self->_next_line();
} while (defined($line) && $line !~ m{ \S }xms);
$self->_buffer_line($line);
}
# Read from the input file descriptor, skipping blank lines and rules.
sub _skip_blank_lines_and_rules {
my ($self) = @_;
my $line;
do {
$line = $self->_next_line();
} while (defined($line) && ($line !~ m{ \S }xms || _is_rule($line)));
$self->_buffer_line($line);
}
##############################################################################
# HTML constructors
##############################################################################
# Output the header of the HTML document. We claim "transitional" XHTML 1.0
# compliance; we can't claim strict solely because we use the value attribute
# in <li> in the absence of widespread implementation of CSS Level 2. Assume
# English output.
#
# $header_ref - Additional information from the headers of the text document
sub _output_header {
my ($self, $header_ref) = @_;
$self->_output(
'<?xml version="1.0" encoding="utf-8"?>', "\n",
'<!DOCTYPE html', "\n",
' PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"', "\n",
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n",
"\n",
'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">',
"\n",
'<head>', "\n",
q{ }, title($self->{title} // $header_ref->{title} // q{}), "\n",
);
if ($self->{style}) {
$self->_output(q{ }, style($self->{style}), "\n");
}
$self->_output(
q{ },
'<meta http-equiv="content-type" content="text/html; charset=utf-8"',
" />\n",
);
if ($self->{sitemap}) {
if (defined($self->{output}) && defined($self->{out_path})) {
my $page = $self->{out_path}->relative($self->{output});
$self->_output($self->{sitemap}->links($page));
}
}
$self->_output("</head>\n\n");
if ($header_ref->{id}) {
$self->_output(comment($header_ref->{id}), "\n");
}
# Add a generator comment.
my $date = strftime('%Y-%m-%d %T -0000', gmtime());
my $version = $App::DocKnot::VERSION;
$self->_output(comment("Converted by DocKnot $version on $date"), "\n\n");
}
# An XML comment.
sub comment {
my @data = @_;
my $data = join ('', @data);
'<!-- ' . $data . ' -->';
}
# A link to a CSS style sheet.
sub style {
my $style = shift;
qq(<link rel="stylesheet" href="$style" type="text/css" />);
}
# Wrap a container around data, keeping the tags on the same line.
sub container {
my ($tag, @data) = @_;
my $data = join ('', @data);
$data = '<' . $tag . '>' . $data;
$tag =~ s/ .*//;
$data =~ s%(\s*)$%</$tag>$1%;
$data;
}
# Output a list item. Takes the indentation, the item, and an optional third
# argument, which if specified is the number to use for the item (using the
# value attribute, which for some reason is deprecated under HTML 4.0 without
# any viable alternative for what I use it for).
sub li {
my ($indent, $data, $value) = @_;
$indent = 0 unless defined $indent;
my $output = '';
if (@INDENT && $INDENT[0][0] eq 'li') {
$output .= "</li>\n";
shift @INDENT;
}
unshift (@INDENT, [ 'li', $indent ]);
my $tag = defined $value ? qq(<li value="$value">\n) : "<li>\n";
$output . $tag . $data;
}
# Wrap a container around data, preserving trailing blank lines outside and
( run in 1.049 second using v1.01-cache-2.11-cpan-39bf76dae61 )