Inline/Text elements may now possess a default element formatter that is triggered by some text within parenthesis immediately after the text but before any other formatters. For anchors, "[[link]](url)" will effectively do the same as "[[link]].href(url)". Some of the code needs to be reworked significantly.

master
kts 2014-12-23 07:55:24 -08:00
parent 17d095e78d
commit a3b57bb001
2 changed files with 30 additions and 18 deletions

View File

@ -393,7 +393,7 @@ sub parseFile {
sub parseOptions {
my $text = $_[0];
my %opts = ();
while ($text =~ m/(\.)([a-zA-Z]*[^\(])(\()([^\)]*)/g) {
while ($text =~ m/(\.|)([a-zA-Z]*[^\(])(\()([^\)]*)/g) {
$opts{$2} = $4;
}
return \%opts;
@ -492,6 +492,7 @@ sub HTML {
sub convertText {
my $text = $_[0];
my @text_patterns = ('\*\*','\*\*', '\/\/','\/\/', '\[\[','\]\]', '\(\(','\)\)', '``', '``', '__','__');
my @default_opts = ("", "", "href", "", "", "");
my @text_replace = ('<b>','</b>', '<i>','</i>', '<a>','</a>', '<small>','</small>', '<code>','</code>', '<u>','</u>');
my @char_patterns = ('&', '<', '>', '"', '\'', '--');
my @char_replace = ('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&mdash;');
@ -511,31 +512,31 @@ sub HTML {
for (my $p = 0; $p <= $#text_patterns; $p+=2) {
my $open = $text_patterns[$p];
my $close = $text_patterns[$p+1];
while ($new_text =~ m/($open)([^$close]*)($close)(\.\S*\(.*?\)|)/g) {
#while ($new_text =~ m/($open)([^$close]*)($close)(\.\S*\(.*\)|)/g) {
#while ($new_text =~ m/($open)([^$close]*)($close)(\.\S*\(.*?\)|)/g) {
while ($new_text =~ m/($open)([^$close]*)($close)((?:\()(.*?)(?:\))|)(\.\S*\(.*?\)|)/g) {
my $converted_text;
if ($p == 4) {
my @media = convertLink($2);
if ($4) {
my $ts = substr($media[0], 0, -1);
my $te = substr($media[0], -1);
$converted_text = $ts.convertOpts(kettext::parseOptions($4)).$te.$media[1];
} else {
$converted_text = $media[0].$media[1];
my $ts = substr($media[0], 0, -1);
my $te = substr($media[0], -1);
my $opts = kettext::parseOptions($6);
if ($5) {
$opts->{$default_opts[$i]} = $5;
}
$new_text =~ s/\Q$1$2$3$4\E/$converted_text/g;
$converted_text = $ts.convertOpts($opts).$te.$media[1];
$new_text =~ s/\Q$1$2$3$4$6\E/$converted_text/g;
} else {
if ($4) {
my $ts = substr($text_replace[$i], 0, -1);
my $te = substr($text_replace[$i], -1);
$converted_text = $ts.convertOpts(kettext::parseOptions($4)).$te.$2.$text_replace[$i+1];
} else {
$converted_text = $text_replace[$i].$2.$text_replace[$i+1];
my $ts = substr($text_replace[$p], 0, -1);
my $te = substr($text_replace[$p], -1);
my $opts = kettext::parseOptions($6);
if ($5) {
$opts->{$default_opts[$i]} = $5;
}
$new_text =~ s/\Q$1$2$3$4\E/$converted_text/g;
$converted_text = $ts.convertOpts($opts).$te.$2.$text_replace[$p+1];
$new_text =~ s/\Q$1$2$3$4$6\E/$converted_text/g;
}
}
$i +=2;
$i++;
}
return $new_text;
}

11
test/default.ktx 100644
View File

@ -0,0 +1,11 @@
Wat.
This is a [[link]].href(1) wat [[link]].href("yo")
Okay
[[link]](1)
[[link]](1).alt(yep)
[[Check out this page!]](http://kettek.exoss.net)