App-DocKnot
view release on metacpan or search on metacpan
lib/App/DocKnot/Spin/Text.pm view on Meta::CPAN
} else {
$last .= "\n$_";
}
}
if (defined $last) {
$self->_output(start($INDENT, 'ul'));
$self->_output(li($INDENT, _format_bold($last)));
}
next;
}
# Check for paragraphs that are entirely numbered lines, and turn them
# into ordered lists without <p> tags.
if (_is_allnumbered $_) {
my @lines = split (/\n/, $_);
for (@lines) {
next unless /\S/;
my ($number) = /^(\d+)/;
$_ = _remove_number($_);
$INDENT = indent $_;
$self->_output(start($INDENT, 'ol'));
$self->_output(li($INDENT, _format_bold($_), $number));
}
next;
}
# Check for bulletted paragraphs and turn them into lists.
if (_is_bullet $_) {
$_ = _remove_bullet($_);
$INDENT = indent $_;
$self->_output(start($INDENT, 'ul'));
$self->_output(li($INDENT, p(_format_bold($_))));
next;
}
# Check for paragraphs quoted with some character and turn them into
# blockquotes provided they don't have inconsistent indentation.
my $quote = _is_quoted ($_);
if ($quote && !$broken) {
$_ = _remove_prefix($_, $quote);
$INDENT = indent $_;
$self->_output(start($INDENT, 'blockquote', p(_format_bold($_))));
next;
}
# Check for numbered paragraphs and turn them into lists.
my $number = _is_numbered ($_);
if (defined $number) {
my $contents = _is_contents ($_);
$_ = _remove_number($_);
$INDENT = indent $_;
s%(\n\s*\S)%<br />$1%g if ($broken || $contents);
$self->_output(start($INDENT, 'ol'));
$self->_output(li($INDENT, p(_format_bold($_)), $number));
next;
}
# Check for things that look like description lists and handle them.
# Note that we don't allow indented description lists, because they're
# usually something we actually want to make <pre>. This is another
# fairly fragile heuristic.
if (_is_description ($_) && defined $INDENT) {
my (@title, $body);
($title[0], $body) = split ("\n", $_, 2);
my ($space) = ($title[0] =~ /^(\s*)/);
while ($body =~ /^$space\S/) {
my $title;
($title, $body) = split ("\n", $body, 2);
push (@title, $title);
}
if ($indent == $INDENT || indent ($body) == $INDENT) {
@title = map { _format_bold($_) } @title;
my $title = join ("<br />\n", @title) . "\n";
$INDENT = indent $body;
$body =~ s%(\n\s*\S)%<br />$1%g if _is_broken $body;
$self->_output(start($indent, 'dl', dt($title)));
$self->_output(start($INDENT, 'dd', p(_format_bold($body))));
next;
}
}
# If the paragraph has inconsistent indentation, we should output it
# in <pre>.
if (_is_offset $_) {
$self->_output(pre(strip_indent($_, $INDENT)));
$self->{pre} = 1;
next;
}
# A sudden indentation change also means the paragraph should be
# blockquoted. We render broken blockquoted text in <pre>, which may
# not be what's wanted for things like quotes of poetry... this is
# probably worth looking at in more detail.
if (defined $INDENT && $indent > $INDENT) {
if ($broken || (lines ($_) == 1 && !_is_sentence $_)) {
$self->_output(pre(strip_indent($_, $INDENT)));
$self->{pre} = 1;
} else {
$INDENT = $indent;
my $paragraph = p(_format_bold($_));
$self->_output(start($INDENT, 'blockquote', $paragraph));
}
next;
}
# Close multiparagraph structure if we've outdented again.
if ($INDENT && $indent < $INDENT) { $self->_output(start($indent)) }
# Looks like a normal paragraph. Establish our indentation baseline
# if we haven't already.
if (!defined $self->{baseline} && !$INDENT) {
$self->{baseline} = $indent;
}
$INDENT = $indent;
s%(\n\s*\S)%<br />$1%g if $broken;
$self->_output(p(_format_bold($_)));
} continue {
$self->{whitespace} = $space;
}
( run in 0.828 second using v1.01-cache-2.11-cpan-b16cb0d3907 )