From effd000ff281f2187bf653b6e1c6aa0fc796c5f9 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 25 Nov 2021 00:45:16 +0100 Subject: [PATCH] source: prepare highlighted lines before output Code cleanup for readability and to facilitate upcoming caching. --- source.plp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/source.plp b/source.plp index f49c8ed..e645cd2 100644 --- a/source.plp +++ b/source.plp @@ -96,24 +96,20 @@ else { my ($type, $contents) = @{$_}; $contents = decode_utf8($contents); my $tag = $type && ($TYPETAG{$type} || 'span'); - my $arg = ''; - print "<$tag$arg class=\"sy-\l$type\">" if $tag; - if (!$type || $type eq 'Constant' - and $contents =~ s{^(['"]?)($incname)(?=\1$)}{}) { - # link other page sources, stylesheets, and javascript - print $1 . showlink($2, "/source/$2"); - } - if (!$type and $contents =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) { - # link perl module names (Xx::Xx...) - print $1 . showlink($2, "/source/$2"); - } - if ($type && $type eq 'Comment' - and $contents =~ s{^(.*? by )(tools/\S+)}{}) { - # link generator scripts (by tools/...) - print $1 . showlink($2, "/source/$2"); - } - print Text::VimColor::_xml_escape($contents); - print "" if $tag; + my $line = Text::VimColor::_xml_escape($contents); + + # link other page sources, stylesheets, and javascript + $line =~ s{ ^(['"]?) \K ($incname) (?=\1$) }{ showlink($2, "/source/$2") }xe + if !$type || $type eq 'Constant'; + # link perl module names (Xx::Xx...) + $line =~ s{ ^\s* \K ([A-Z]\w+(?:::\w+)+) (?![^;\s]) }{ showlink($1, "/source/$1") }xe + if !$type; + # link generator scripts (by tools/...) + $line =~ s{ ^.*? by\ \K (tools/\S+) }{ showlink($1, "/source/$1") }xe + if $type && $type eq 'Comment'; + + $line = qq(<$tag class="sy-\l$type">$line) if $tag; + print $line; } say ''; } -- 2.30.0