Text-Restructured
view release on metacpan or search on metacpan
lib/Text/Restructured.pm view on Meta::CPAN
my $nest_trailer = defined $nest_start && defined $MARK_END{$nest_start} ?
$MARK_END{$nest_start} : "\001";
while (! $match &&
(my @s = split /((\S|\A)($MARK_END{$start})(?=$MARK_END_TRAILER|$nest_trailer|\n))/, $text, 2) > 1) {
my ($next, $after);
($next, $end,$after) = ("$s[0]$s[2]", $s[3], $s[-1]);
#print STDERR "$lineno: #$start#$next#$end#$s[-1]\n";
if (("$start$end" =~ /^_/ && $start ne '_`' &&
($next =~ /([\._-])\1/ || $next =~ /[\`\]]$/)) ||
($start eq '[' && $next !~ /^(?=.)[\#\*]?$self->{CITE_CHARS}*$/)) {
$mid = "$next$end";
$text = $after;
last;
}
$match = 1;
my @content;
if ($MARK_TAG_START{$start} ne 'literal') {
if (substr($next,-1, 1) eq "\\") {
# It's backslash quoted; not a real end mark
substr($next,-1, 1) = "\\$end";
$match = 0;
}
}
$mid = "$mid$next";
$text = $after;
}
#print STDERR "InlineFindEnd -> [$match][$mid][$end][$text]\n";
return ($match, $mid, $end, $text);
}
# Finds the place where inline markup starts.
# Arguments: text, character preceding text
# Returns: Boolean indicating markup was found, characters preceding markup
# start, start markup string, characters after markup start
sub InlineStart : method {
#print STDERR "InlineStart(",join(',',@_),")\n";
my ($self, $text, $previous) = @_;
my $arg = $text;
my $pre = '';
while (#do{print STDERR "[$text]\n";1} &&
$text =~ m(^(.*?)(^|[-\'\"\(\[\{</: ])(?:($MARK_START)(\S)|(?=(?=[^-_\'\"\(\[\{</: \\\n])(\S*[^\\\s])__?($MARK_END_TRAILER|\n))|(?=$Text::Restructured::URIre::absoluteURI|$EMAIL))(.*))mos) {
my ($processed, $prechar,$start,$postchar,$after) =
map defined $_ ? $_ : '', ($1,$2,$3,$4,$7);
my $pending = $start if $start eq '[';
$previous = substr($pre, -1) if $pre ne '';
my $pchar = $prechar eq '' ? $previous : $prechar;
#print STDERR "<$pchar><$start><$postchar><$after>\n";
my $validstart = 1;
if (defined $pchar && defined $MATCH_BRACE{$pchar} &&
$postchar eq $MATCH_BRACE{$pchar} ||
$postchar eq $start && $start ne '') {
# It's within quotes
$processed .= "$prechar$start$postchar";
$text = $after;
$validstart = 0;
}
elsif ($start eq '' && defined $pchar &&
$pchar !~ m!(\A|[-\'\"\(\[\{</: \\])$!) {
# It seems to be a reference, but prechar isn't allowed
my @s = split m!(([-\'\"\(\[\{</: \\])|(__?)(?=$MARK_END_TRAILER|\n))!, $text,2 ;
$pchar = $s[2] if defined $s[2];
my $anon = defined $s[3] ? $s[3] : '';
($processed,$after) = ("$processed$s[0]$pchar$anon","$s[-1]");
$validstart = 0;
$text = $after;
}
elsif ($start eq '' &&
(my @s = split /(($Text::Restructured::URIre::scheme):(?:$Text::Restructured::URIre::hier_part|$Text::Restructured::URIre::opaque_part))/o,
$text, 2) > 1) {
# It seems to be implicit markup, but it's not a recognized scheme
my $scheme = $s[2];
if (! $IMPLICIT_SCHEME{$scheme}) {
($processed, $after) = ("$s[0]$s[1]", "$s[-1]");
$validstart = 0;
$text = $after;
}
else {
$processed = "$processed$prechar";
}
}
else {
$processed = "$processed$prechar";
$after = "$postchar$after";
}
$pre .= $processed;
#print STDERR "InlineStart -> [$validstart][$pre][$start][$after]\n" if $validstart;
return ($validstart, $pre, $start, $after) if $validstart;
}
#print STDERR "InlineStart -> 0\n";
return 0;
}
# Returns whether a reStructuredText string represents a valid table object.
# Arguments: string
# Returns: true or false
sub IsTable : method {
my ($self, $text) = @_;
chomp $text;
my @lines = split(/\n/, $text);
my $first = $lines[0];
return 0 unless defined $first;
# Check for a validly constructed grid table
if ($first =~ /^[+]([-=]+[+])+ *$/) {
my $l;
for ($l=1; $l < @lines; $l++) {
$_ = $lines[$l];
return 0 unless /^[|+].*[|+] *$/;
return 1 if $l > 1 && /^[+][+-]+[+] *$/;
}
return 0;
}
# Check for a validly constructed simple table
elsif ($first =~ /^=+( +=+)+ *$/) {
return 1;
}
return 0;
}
( run in 0.938 second using v1.01-cache-2.11-cpan-71847e10f99 )