From: Sergey Matveev Date: Sat, 31 May 2025 11:14:50 +0000 (+0300) Subject: Ability to use images in links X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e3bd8a70a2251538a7f7363be9417e7d3f90ef21;p=swg.git Ability to use images in links --- diff --git a/FORMAT b/FORMAT index e789d9f..28954aa 100644 --- a/FORMAT +++ b/FORMAT @@ -8,8 +8,9 @@ role only (currently) during HTML generation. * => URL[ optional text] Creates {optional text|URL} link in HTML. -* img URL[ optional text] +* img URL[ optional text][ => URL-A] Creates in HTML. + If "=> URL" is specified, then . * |... Just inserts raw ... line to HTML output as-is. * #... @@ -17,5 +18,5 @@ role only (currently) during HTML generation. * do-backs Forcefully creates a table with all backlinks to the page. * <<[indent][page] - Include contents of the specified page. Brackets around - [page] are for making a link to page. indent is optional. + Include contents of the specified page. indent is optional. + Brackets around [page] are for making a link to page. diff --git a/swg b/swg index 9d84468..b42e7bc 100755 --- a/swg +++ b/swg @@ -268,34 +268,42 @@ END_HTML if (/${CR}$/) { chop; my $head = q{}; - my @cols; - if (/^(\s*)(.*)$/) { + my $cmd = $_; + if (/^(\s+)(.*)$/) { $head = $1; - @cols = split /\s+/, $2; - } else { - @cols = split /\s+/; + $cmd = $2; } - if ($cols[0] eq q{=>}) { - my $t = ($#cols > 1) ? (join q{ }, @cols[2..$#cols]) : $cols[1]; + if ($cmd =~ /^=> (\S+)\s?(.*)$/) { + my $t = ($2 eq q{}) ? $1 : $2; $t = htmlescape $t; $t =~ s/"/\&guot;/g; - $_ = "$head=> $t"; - } elsif ($cols[0] eq q{img}) { - if ($#cols > 1) { - my $t = htmlescape join q{ }, @cols[2..$#cols]; + $_ = "$head=> $t"; + } elsif ($cmd =~ /^img (\S+)\s?(.*) => (\S+)$/) { + if ($2 eq q{}) { + $_ = "$head"; + } else { + my $t = $2; + $t = htmlescape $t; $t =~ s/"/\&guot;/g; - $_ = "$head\"$t\""; + $_ = "$head\"$t\""; + } + } elsif ($cmd =~ /^img (\S+)\s?(.*)$/) { + if ($2 eq q{}) { + $_ = "$head"; } else { - $_ = "$head"; + my $t = $2; + $t = htmlescape $t; + $t =~ s/"/\&guot;/g; + $_ = "$head\"$t\""; } - } elsif ($cols[0] eq q{do-backs}) { + } elsif ($cmd eq q{do-backs}) { $doBacks = 1; return; - } elsif (/^\s*#/) { + } elsif ($cmd =~ /^#/) { return; - } elsif (/^\s*[|]/) { - $_ = $head . substr $_, 1 + (index $_, q{|}); - } elsif (/^\s*<<(.*)\[([^[]+)\]/) { + } elsif ($cmd =~ /^[|]/) { + $_ = $head . substr $cmd, 1 + (index $cmd, q{|}); + } elsif ($cmd =~ /^<<(.*)\[([^[]+)\]$/) { my $indentOrig = $indent; $indent .= "${head}$1"; open my $fh, q{<:encoding(UTF-8)}, $2 or croak "$!"; @@ -304,7 +312,7 @@ END_HTML $indent = $indentOrig; return; } else { - croak "unknown $cols[0] command: $page\n"; + croak "unknown \"$cmd\" command: $page\n"; } } else { $_ = htmlescape $_;