]> lifelog.hopto.org Git - LifeLog.git/commitdiff
prep. for 2.5 finale.
authorWill Budic <redacted>
Thu, 20 Jul 2023 11:09:03 +0000 (21:09 +1000)
committerWill Budic <redacted>
Thu, 20 Jul 2023 11:09:03 +0000 (21:09 +1000)
dbLifeLog/main.cnf
htdocs/cgi-bin/config.cgi
htdocs/cgi-bin/index.cgi
htdocs/cgi-bin/index.cnf
htdocs/cgi-bin/main.cgi
htdocs/cgi-bin/system/modules/MarkdownPlugin copy.pm [new file with mode: 0644]
htdocs/cgi-bin/system/modules/MarkdownPlugin.pm
htdocs/cgi-bin/system/modules/Settings.pm

index 4d631f634d4783a6a45483ab3a4770809871cede..8a340c3e7c508d482a35e9bd24d139abb40a36fe 100644 (file)
@@ -81,7 +81,7 @@ BankingPlugin->banking.pl
 # Use/see anon properties before, enabling changing settings from this actual config file.
 #
 <<CONFIG<4>
-00|$RELEASE_VER = 2.4`LifeLog Application Version.
+00|$RELEASE_VER = 2.5`LifeLog Application Version.
 01|$REC_LIMIT   = 25`Records shown per page.
 03|$TIME_ZONE   = Australia/Sydney`Time zone of your country and city.
 05|$PRC_WIDTH   = 80`Default presentation width for pages.
@@ -105,6 +105,7 @@ BankingPlugin->banking.pl
 42|$DISP_ALL    = 1`Display whole log entry, default -> 1=true, 0=false for display single line only.
 44|$TRANSPARENCY= 1`Should log panel be transparent, default is yes or on.
 50|$CURR_SYMBOL = &#36;`Currency symbol.
+52|$AUDIO_ENABLED=1`Enable/Disable audio on some events and actions.
 >>
 <<CAT<3>
 01|Unspecified `For quick uncategorized entries.
index 8204b4bd0c8e67a29476accca1f22e6910cc08f6..da10bb572ba81bba4a90cbbadd22cd9c89da377b 100755 (executable)
@@ -289,7 +289,7 @@ while ( my @row = $dbs->fetchrow_array() ) {
                     <option value="1" $u>True</option>
                     </select>);
     }
-    elsif ( $n eq "DISP_ALL" ) {
+    elsif ( $n eq "DISP_ALL" or $n eq 'AUDIO_ENABLED') {
         my ( $l, $u ) = ( "", "" );
         if ( $v == 0 ) {
             $l = "SELECTED";
@@ -306,8 +306,7 @@ while ( my @row = $dbs->fetchrow_array() ) {
         or $n eq 'TRACK_LOGINS'
         or $n eq 'DEBUG'
         or $n eq 'TRANSPARENCY'
-        or $n eq 'AUTO_LOGOFF' )
-    {
+        or $n eq 'AUTO_LOGOFF') {
         my ( $l, $u ) = ( "", "" );
         if ( $v == 0 ) {
             $l = "SELECTED";
index 9a755b9943d2a8302d63a12efb2889a5eaf8477c..7110fe10d0e57602192005aae137b1118bbd7329 100755 (executable)
@@ -14,7 +14,6 @@ use strict;
 use warnings;
 use Exception::Class ('LifeLogException');
 use Syntax::Keyword::Try;
-use DateTime;
 ##
 # We use dynamic perl compilations. The following ONLY HERE required to carp to browser on 
 # system requirments or/and unexpected perl compiler errors.
@@ -30,6 +29,7 @@ BEGIN {
 }
 
 
+
 use lib "system/modules";
 require CNFParser;
 require CNFNode;
index 62e998e54b7321ee6c408e9aa301e3cb73182c0f..40da71652098cdc82bdc2f6c6f47d4103574291f 100644 (file)
@@ -319,8 +319,6 @@ function loadDocResult(content){
 
 <<INFO_MD<ESCAPED>
 
-```cnf
-
 ### INFO
 \> This Page is the Documentation listing coming with the [LifeLog](https://github.com/wbudic/LifeLog) Application.
 \>
@@ -341,21 +339,3 @@ function loadDocResult(content){
 >>
 <<1>>
 
-//Following for debug purposess and tests.
-
-```CNF
-
-
-\<\<\<CONST
-$APP_NAME       = "Test Application"
-$APP_VERSION    = v.1.0
-\>\>\>
-
-\<\<B\<{Text To Bold}\>\>
-\<\<I\<{Text To Italic}\>\>
-
-\<\<$APP_DESCRIPTION\<CONST\>
-This application presents just
-a nice multi-line template.
-\>\>
-```
\ No newline at end of file
index 8edec27d5319a4bd7b8645d5e43db77deae04887..7be12474047559c2366f1f675149a33752358b95 100755 (executable)
@@ -1100,7 +1100,21 @@ my $help = &help;
 ##################################
 #  Final Page Output from here!  #
 ##################################
-
+my $audio = &Settings::audioEnabled ? qq(
+       <audio id="au_door_chime" enabled preload="auto" 
+    src="wsrc/Miki-Matsubara-WASH-WASH.mp3">
+        Your browser does not support the
+        <code>audio</code> element.
+</audio>
+<audio id="dutchie_chime"  enabled preload="auto"   src="wsrc/dutchie.mp3">
+        Your browser does not support the
+        <code>audio</code> element.
+</audio>
+<audio id="dutchie_close_chime"  enabled preload="auto"   src="wsrc/dutchie-close.mp3">
+        Your browser does not support the
+        <code>audio</code> element.
+</audio>
+):"";
 toBuf (
        qq(
 $sideMenu
@@ -1120,20 +1134,7 @@ $tail
 <script type="text/javascript">
         var AUTOWORDS = [$autowords];
 </script>
-<audio id="au_door_chime"  enabled preload="auto" 
-    src="wsrc/Miki-Matsubara-WASH-WASH.mp3">
-        Your browser does not support the
-        <code>audio</code> element.
-</audio>
-<audio id="dutchie_chime"  enabled preload="auto"   src="wsrc/dutchie.mp3">
-        Your browser does not support the
-        <code>audio</code> element.
-</audio>
-<audio id="dutchie_close_chime"  enabled preload="auto"   src="wsrc/dutchie-close.mp3">
-        Your browser does not support the
-        <code>audio</code> element.
-</audio>
-)
+$audio)
 );
 
 outputPage();
diff --git a/htdocs/cgi-bin/system/modules/MarkdownPlugin copy.pm b/htdocs/cgi-bin/system/modules/MarkdownPlugin copy.pm
new file mode 100644 (file)
index 0000000..f299fbd
--- /dev/null
@@ -0,0 +1,593 @@
+package MarkdownPlugin;
+
+use strict;
+use warnings;
+no warnings qw(experimental::signatures);
+use Syntax::Keyword::Try;
+use Exception::Class ('MarkdownPluginException');
+use feature qw(signatures);
+use Date::Manip;
+##no critic ControlStructures::ProhibitMutatingListFunctions
+
+our $TAB = ' 'x4;
+our $PARSER;
+
+sub new ($class, $fields={Language=>'English',DateFormat=>'US'}){      
+
+    if(ref($fields) eq 'REF'){
+       warn "Hash reference required as argument for fields!"
+    }
+    my $lang =   $fields->{'Language'};
+    my $frmt =   $fields->{'DateFormat'};
+    Date_Init("Language=$lang","DateFormat=$frmt");            
+    $fields->{'disk_load'} = 0 if not exists $fields->{'disk_load'};
+   
+    return bless $fields, $class
+}
+
+###
+# Process config data to contain expected fields and data.
+###
+sub convert ($self, $parser, $property) {    
+try{    
+    my ($item, $script) =  $parser->anon($property);
+    $PARSER = $parser;
+    die "Property not found [$property]!" if !$item;
+
+    my $ref = ref($item); my $escaped = 0; $script = $item;
+    if($ref eq 'CNFNode'){
+       $script = $item->{script}  
+    }elsif($ref eq 'InstructedDataItem'){
+       $script = $item->{val};
+       $escaped = $item->{ins} eq 'ESCAPED'
+    }elsif($script !~ /\n/ and -e $script ){
+        my $file = $parser->anon($property);
+        $script = do {
+        open my $fh, '<:encoding(UTF-8)', $script or MarkdownPluginException->throw("File not avaliable: $script");
+        local $/;
+        <$fh>;    
+        };
+    }
+    if($escaped){        
+        $script =~ s/\\</</gs;
+        $script =~ s/\\>/>/gs;
+        #$script =~ s/\n/<br>/gs;
+    }
+    my @doc = @{parse($self,$script)};
+    $parser->data()->{$property} =  $doc[0];
+    $parser->data()->{$property.'_headings'} = $doc[1];
+   
+}catch($e){
+        MarkdownPluginException->throw(error=>$e ,show_trace=>1);
+}}
+
+
+package HTMLListItem {    
+    sub new{
+        my $class = shift;
+        my ($type,$item,$spc) = @_;
+        my @array = ();
+        return bless{type=>$type,item=>$item,spc=>$spc,list=>\@array},$class;
+    }
+    sub parent($self) {
+        return  exists($self->{parent}) ? $self->{parent} : undef
+    }
+    sub add($self, $item){
+        push @{$self->{list}}, $item;        
+        $item ->{parent} = $self;
+    }    
+    sub hasItems($self){        
+        return @{$self->{list}}>0
+    }
+    sub toString($self){        
+        my $t = $self->{type};
+        my $isRootItem = $self -> {spc} == 0 ? 1 : 0;
+        my $hasItems   = $self->hasItems();
+        my $hasParent  = exists($self->{parent});
+        my ($ret,$recurse)=("",0);
+        if ($hasItems) {
+           if($isRootItem) {
+            $ret = "<$t>\n<li>".$self -> {item}."\n";            
+           }else{
+            $ret = "<$t>\n<li>".$self -> {item}."</li>\n"
+           }
+        }else{
+           $ret = "<li>".$self -> {item}."</li>\n"
+        }
+        foreach my $item(@{$self->{list}}){
+            if($item->hasItems()){
+               $ret .= $item->toString(); $recurse++
+            }else{
+               my $it = $item->{type};
+               $it = 'li' if $it eq 'ol' || $it eq 'ul';
+               $ret .= "<$it>".$item->{item}."</$it>\n";
+               $isRootItem = $item->{spc};
+            }
+        }
+        if($hasItems){
+           if($isRootItem) {
+              $ret .= "\n"
+           }else{ 
+              $ret .= "</$t>\n"
+           }
+        }
+        return $ret
+    }
+}
+
+sub setCodeTag($tag, $class){
+    if($tag){
+        $tag = lc $tag;        
+        if($tag eq 'html' or $tag eq 'cnf' or $tag eq 'code' or $tag eq 'perl'){
+            $class = $tag;
+            $tag = 'div';
+        }else{
+            $tag = 'pre' if($tag eq 'sh' or $tag eq 'bash');
+        }
+        if($tag eq 'perl'){
+            $class='perl'; 
+            $tag  ='div';                                   
+        }
+    }else{
+        $tag = $class = 'pre';
+    }
+    return [$class, $tag]
+}
+
+sub parse ($self, $script){
+try{
+    my ($buffer, $para, $ol, $lnc); 
+    my @list; my $list_end; my $ltype=0;  my $nix=0; my $nplen=0; my $list_item;
+    my @titels;my $code = 0; my ($tag, $class);  my $pml_val = 0;  my ($bqte, $bqte_nested,$bqte_tag);
+    $script =~ s/^\s*|\s*$//;
+    foreach my $ln(split(/\n/,$script)){        
+           $ln =~ s/\t/$TAB/gs; $lnc++;
+        if($ln =~ /^```(\w*)\s(.*)```$/g){
+            $tag = $1;
+            $ln  = $2;
+            my @code_tag = @{ setCodeTag($tag, "") }; 
+            $buffer .= qq(<$code_tag[1] class='$code_tag[0]'>$ln</$code_tag[1]>\n);
+            next
+        }elsif($ln =~ /^\s*```(\w*)/){
+            my $bfCode;
+            if(!$tag){
+                my @code_tag = @{ setCodeTag($1, $1) };
+                $class = $code_tag[0];         
+                $tag = $code_tag[1] if !$tag;
+            }
+            if($code){
+               if($para){ 
+                  $bfCode .= "$para\n"
+               }
+               $bfCode .= "</$tag>"; undef $para;
+               $code = 0; undef $tag;
+               if($list_item){                  
+                  $list_item -> {item} = $list_item -> {item} . $bfCode.'<br>';
+                  $list_item =  $list_item -> parent();
+                  next;
+               }
+            }else{
+               $bfCode .= "<$tag class='$class'>"; 
+               if($class eq 'perl'){
+                  $bfCode .= qq(<h1><span>$class</span></h1>);
+                  $code = 2;
+                }else{
+                  if($class eq 'cnf' or $class eq 'html'){
+                     $bfCode .= '<h1><span class="cnf"><a title="M.C. Hammer -- Can\'t  touch this!" href="/" style="text-decoration: none;">Perl&nbsp;'.uc $class.'</a></span></h1>'
+                  }
+                  $code = 1
+                }
+            }
+            if($list_item){   
+                my $new = HTMLListItem->new('dt', "<br>$bfCode", $list_item ->{spc});
+                $list_item -> add($new);
+                $list_item =  $new;
+                $list_end=0;
+            }else{
+                $buffer .= "$bfCode\n";
+            }
+        }elsif(!$code && $ln =~ /^\s*(#+)\s*(.*)/){
+            my $h = 'h'.length($1);
+            my $title = $2; 
+            $titels[@titels] = {$lnc,$title};
+            $buffer .= qq(<$h>$title</$h><a name=").scalar(@titels)."\"></a>\n"
+        }
+        elsif(!$code &&  ($ln =~ /^(\s*)(\d+)\.\s(.*)/ || $ln =~ /^(\s*)([-+*])\s(.*)/)){
+            
+            my $spc = length($1);
+            my $val = $3 ? ${style($3)} : "";
+            my $new = HTMLListItem->new(($2=~/[-+*]/?'ul':'ol'), $val, $spc);
+
+            if(!$list_item){                
+                $list_item = $new;
+                $list[@list] = $list_item;
+                $nplen = $spc;
+                $list_end = 0;
+                
+            }elsif($spc>$nplen || $list_end){                
+                $list_item -> add($new);                
+                $list_item = $new;
+                $nplen = $spc;
+                $list_end = 1;             
+            }else{                
+               while($list_item->{spc}>=$spc && $list_item -> parent()){
+                     $list_item = $list_item -> parent();
+               }                
+               if ( !$list_item ){
+                $list_item = $new;
+                $list_end  = 0;
+               }else{
+                     $list_item -> add($new);
+                     $list_item = $new;                
+               }
+            }            
+        }elsif(!$code && $ln =~ /(^|\\G)[ ]{0,3}(>+) ?/){
+            my $nested = length($2);
+             $ln =~ s/^\s*\>+//;
+            ($ln =~ /^(\s+)   (\d+) \.\s (.*)/x || $ln =~ /^(\s*) ([-+*]) \s(.*)/x);
+            if($2 && $2 =~ /[-+*]/){
+                $bqte_tag = "ul";
+            }elsif($2){
+                $bqte_tag = "ol";
+            }else{
+                $bqte_tag = "p";
+            }
+            if(!$bqte_nested){
+                $bqte_nested = $nested;
+                $bqte .="<blockquote><$bqte_tag>\n"
+            }elsif($bqte_nested<$nested){
+                $bqte .="</$bqte_tag><blockquote><$bqte_tag>";
+                $bqte_nested = $nested;
+            }elsif($bqte_nested>$nested){
+                $bqte .="</$bqte_tag></blockquote><$bqte_tag>";
+                $bqte_nested--;
+            }
+            if($ln !~ /(.+)/gm){
+               $bqte .= "\n</$bqte_tag><p>\n"               
+            }else{
+                if($bqte_tag eq 'p'){
+                   $ln =~ s/^\s*//g;
+                   $bqte .= ${style($ln)}."</br>";
+                }else{
+                   $ln =~ s/^\s*[-+*]\s*|^\s*\d+\.\s*//g; 
+                   $bqte .= "<li>".${style($ln)}."</li>\n"; 
+                }
+            }            
+        }
+        elsif(!$code && $ln =~ /^\s*\*\*\*/){
+            if($para){
+                $para   .= qq(<hr>\n)
+            }else{
+                $buffer .= qq(<hr>\n)
+            }
+        }
+        elsif($ln =~ /^\s*(.*)/ && length($1)>0){
+            if($code){
+                 my $v=$1;
+                if($tag eq 'pre' && $code == 1){
+                    $v =~ s/</&#60;/g;
+                    $v =~ s/>/&#62;/g;
+                    $para .= "$v\n"; 
+                }elsif($code == 2){   
+                    $para .= code2HTML($v)."<br>\n";
+                }else{           
+                    $v = inlineCNF($v);
+                    if(length($v) > length($ln)){
+                       $para .= qq($v<br>);
+                       next
+                    }
+
+                    $v =~ m/  ^(<{2,3}) ([\$@%]*\w*)$ 
+                            | ^(>{2,3})$
+                            | (<<) ([\$@%]*\w*) <(\w+)>
+                     /gx;
+
+                    if($1&&$2){
+                        my $t = $1;  
+                        my $i = $2;  
+                        $t =~ s/</&#60;/g;                      
+                        $para .= qq(<span class='B'>$t</span><span class='ins'>$i</span><br>);
+                        $pml_val = 1;
+                        next;
+                        
+                    }elsif($3){
+                        my $t = $3; 
+                        $t =~ s/>/&#62;/g;  
+                        $para .= "<span class='B'>$t</span><br>\n";
+                        $pml_val = 0;
+                        next;
+                    }elsif($4&&$5&&6){
+                        my $t = $4;   
+                        my $v = $5;
+                        my $i = $6;
+                        $t =~ s/</&#60;/g;
+                        $para .= qq(<span class='B'>$t</span><span class='pv'>$v</span>
+                                    <span class='B'>&#60;</span><span class='ins'>$i</span><span class='B'>&#62;</span><br>);
+                        $pml_val = 1;
+                        next;
+
+                    }
+                    
+                    $v =~ m/ ^(<<)  ([@%]<) ([\$@%]?\w+) ([<>])
+                            |^(<{2,3})                          
+                                ([\$@%\w]+)\s*
+                                      <*([^>]+)
+                              (>{2,3})$
+                            
+                           /gx;# and my @captured = @{^CAPTURE};
+                    
+                    if($5&&$6&&$7&&$8){
+                        my $t = $5;
+                        my $v = $6;
+                        my $i = $7;
+                        my $c = $8;
+                        $t =~ s/</&#60;/g;
+                        $c =~ s/>/&#62;/g;
+                        $pml_val = 1;                       
+                        $para .= qq(<span class='B'>$t</span><span class='pv'>$v</span><span class='B'>&#60;</span><span class='pi'>$i</span><span class='B'>$c</span><br>);
+                       
+                    }elsif($5&&$6){
+                        my $t = $5;
+                        my $i = $6;
+                        $t =~ s/</&#60;/g; $pml_val = 1;
+                        $para .= qq(<span class='B'>$t</span><span class='pi'>$i</span><br>);
+
+                    }elsif($1 && $2 && $3){
+                        
+                        $pml_val = 1;
+                        $para .= qq(<span class='B'>&#60;&#60;$2<\/span><span class='pv'>$3</span><span class='B'>&#62;<\/span><br>);
+                       
+                    }elsif($8){
+                        my $t = $8; 
+                        $t =~ s/>/&#62;/g;  $pml_val = 0;
+                        $para .= "<span class='B'>$t</span><br>\n";
+                    }
+                    else{
+                        if($pml_val){
+                            $v =~ m/(.*)([=:])(.*)/gs;
+                            if($1&&$2&&$3){
+                                $para .= "<span class='pv'>$1</span> <span class='B'>$2</span> <span class='pn'>$3</span> <br>\n";
+                            }else{
+                                $para .= " <span class='pn'>$v</span><br>\n";
+                            }
+                        }else{
+                            $para .= "$v<br>\n";
+                        }
+                    }
+                }
+                
+            }else{
+                if($bqte){
+                    while($bqte_nested-->0){$bqte .="</$bqte_tag></blockqoute>\n"}
+                    $para   .= $bqte;
+                    undef $bqte;
+                }
+                $para .= ${style($1)}."\n"         
+            }
+        }else{            
+            
+            if(@list && ++$list_end>1){                
+                foreach (@list){
+                         $buffer .= $_-> toString()    
+                }               
+                undef @list; undef $list_item;
+            }
+            elsif($para){
+               if($code){
+                    $buffer .= $para;
+               }else{
+                $buffer .= qq(<p>$para</p><br>\n);
+               }
+               $para=""
+            }
+        }
+    }
+    if($bqte){
+        while($bqte_nested-->0){$bqte .="\n</$bqte_tag></blockquote>\n"}
+        $buffer .= $bqte;        
+    }    
+    if(@list){
+        foreach (@list){
+                    $buffer .= $_-> toString()    
+        }  
+    }
+    $buffer .= qq(<p>$para</p>\n) if $para;    
+
+return [\$buffer,\@titels]
+}catch($e){
+        MarkdownPluginException->throw(error=>$e ,show_trace=>1);
+}}
+
+sub code2HTML($v){
+        $v =~ s/([,;=\(\)\{\}\[\]]|->)/<span class='opr'>$1<\/span>/g;
+        $v =~ s/(['"].*['"])/<span class='str'>$1<\/span>/g;        
+        $v =~ s/(my|our|local|use|lib|require|new|while|for|foreach|while|if|else|elsif)/<span class='B'>$1<\/span>/g;                    
+        $v =~ s/(\$\w+)/<span class='pi'>$1<\/span>/g;
+        return $v
+}
+
+sub inlineCNF($v){
+
+    # $v =~ m/ ^(<<)  ([@%]<) ([\$@%]?\w+) ([<>])
+    #                         |^(<{2,3})                          
+    #                             ([^>]+)
+    #                                 ( (<|>\w*>) | [<|>] (\w*)  | (>{2,3})\s*)$
+    #             /gmx;
+
+
+    $v =~ m/    ^(<<)  ([@%]<) ([\$@%]?\w+) ([<>])
+                                |^(<{2,3})                          
+                                    ([^>]+)
+                                            ( 
+                                            (<|>\w*>?) | [<|>] (\w*) 
+                                            )
+                                |(>{2,3})$ 
+    /gmx;
+
+    if($5&&$6&&$7){
+        my ($o,$oo,$i,$isVar,$sep,$var,$prop,$c,$cc);
+        $oo = $5; $var  = $6; $cc = $7;        
+        
+        if($cc=~/^([<|>])([\w ]*)(>+)/){
+           $o = $1;
+           $i = $2;
+           $c = $3;
+           if($i && $i ne $c){              
+              $o =~ s/</&#60;/g;
+              $o =~ s/>/&#62;/g;
+              my $iv = $i;
+              if($var=~/^(\w+)([<|>])(\w+)/){
+                 $var = $1;
+                 $sep = $2;
+                 $i = $3;
+                 $sep =~ s/</&#60;/g;
+                 $sep =~ s/>/&#62;/g;
+                 $prop = qq(<span class='pn'>$var</span><span class='B'>$sep</span><span class='pi'>$i</span><span class='B'>&#62</span><span class='pv'>$iv</span>);
+                 $cc   =~ s/$iv//;                 
+              }elsif($PARSER->isReservedWord($i)){
+                 $prop = qq(<span class='pn'>$var</span><span class='B'>$o</span><span class='pv'>$i</span><span class='B'>$c</span>);
+              }else{
+                 $prop = qq(<span class='pn'>$var</span><span class='B'>$o</span><span class='pv'>$i</span>);
+                 $cc   =~ s/$i//;
+              }
+           }elsif($var=~/^(\w+)([<|>])(\w+)/){
+                $var = $1;
+                $sep = $2;
+                $i   = $3;
+                $sep =~ s/</&#60;/g;
+                $sep =~ s/>/&#62;/g;
+                $prop = qq(<span class='pn'>$var</span><span class='B'>$sep</span><span class='pv'>$i</span>);
+           }else{
+                $cc .='>' if length($oo) != length($cc)
+           }
+        }
+        $oo =~ s/</&#60;/g;        
+        $cc =~ s/>/&#62;/g;     
+        
+        if(!$prop){
+            $v = $var;
+            $v =~ m/^(\w+\$*)\s*([<|>])*([^>]+)*/;
+            $var = $1; 
+            $isVar = $2;
+            $i = $3 if $3;
+            $prop = $v;
+            if($isVar){
+                $isVar =~ s/</&#60;/g;
+                $isVar =~ s/>/&#62;/g;        
+                if($i){
+                    $v =~ s/^\w+\s*\s*(<|>)*([^>]*)*/<span class='pn'>$var<\/span><span class='B'>$isVar<\/span><span class='pv'>$i<\/span>/;
+                }else{
+                    $v =~ s/^\w+\s*\s*(<|>)*/<span class='pi'>$var<span class='B'>$isVar<\/span><\/span>/;
+                }
+                $prop = $v
+            }else{
+                $prop = propValCNF($i);
+                $i =~ s/\{/\\\}/;
+                $v =~ s/\s$i$/$prop/;
+                if($PARSER->isReservedWord($var)){
+                        $v =~ s/^\w+/<span class='pi'>$var<\/span>/;
+                }else{
+                        $v =~ s/^\w+/<span class='pn'>$var<\/span>/;
+                }
+                $prop = $v;                
+            }
+        }
+
+        $v = qq(<span class='B'>$oo</span>$prop</span><span class='B'>$cc</span>);
+    }
+    elsif($5&&$6){
+        my $t = $5;
+        my $i = $6;
+        my $c = $7; $c = $8 if !$c;
+        $t =~ s/</&#60;/g; 
+        $c =~ s/>/&#62;/g if $c;
+        $v = qq(<span class='B'>$t</span><span class='pi'>$i</span>$c);
+    }            
+    elsif($1 && $2 && $3){
+        my $ins  = $2;
+        my $prop = propValCNF($3);
+        $v = qq(<span class='B'>&#60;&#60;$ins<\/span>$prop<span class='B'>&#62;<\/span>);        
+    }
+    return $v
+}
+sub propValCNF($v){    
+    $v =~ m/(.*)([=:])(.*)/gs;
+    if($1&&$2&&$3){
+       $v = "&nbsp;<span class='pi'>$1</span><span class='O'>$2</span><span class='pv'>$3</span>";
+    }else{
+       $v = "&nbsp;<span class='pv'>$v</span>";
+    }
+    return $v;
+}
+
+sub style ($script){
+    MarkdownPluginException->throw(error=>"Invalid argument passed as script!",show_trace=>1) if !$script;
+    #Links <https://duckduckgo.com>
+    $script =~ s/<(http[:\/\w.]*)>/<a href=\"$1\">$1<\/a>/g;
+    $script =~ s/(\*\*([^\*]*)\*\*)/\<em\>$2<\/em\>/gs;
+    $script =~ s/(\*([^\*]*)\*)/\<strong\>$2<\/strong\>/gs;
+    $script =~ s/__(.*)__/\<del\>$1<\/del\>/gs;
+    $script =~ s/~~(.*)~~/\<strike\>$1<\/strike\>/gs;
+    my $ret = $script;
+    #Inline code
+    $ret =~ m/```(.*)```/g;
+    if($1){
+        my $v = inlineCNF($1);        
+        $ret =~ s/```(.*)```/\<span\>$v<\/span\>/;         
+    }
+    
+    #Images
+    $ret =~ s/!\[(.*)\]\((.*)\)/\<div class="div_img"><img class="md_img" src=\"$2\"\ alt=\"$1\"\/><\/div>/;
+    #Links [Duck Duck Go](https://duckduckgo.com)
+    $ret =~ s/\[(.*)\]\((.*)\)/\<a href=\"$2\"\>$1\<\/a\>/;
+    return \$ret;
+}
+
+###
+# Style sheet used  for HTML conversion. 
+# Link with <*<MarkdownPlug::CSS>*> in a TREE instructed property.
+###
+use constant CSS => q/
+
+div .cnf {
+    background: aliceblue;
+}
+.cnf h1 span  {
+    color:#05b361;
+    background: aliceblue;
+}
+    .B {
+        color: #c60000;
+        padding: 2px;        
+    }
+
+    .Q {
+        color: #b7ae21;  
+        font-weight: bold;
+    }
+
+    .pn {
+        color: #6800ff;        
+    }
+
+    .pv {
+        color: #883ac8;        
+    }
+
+    .pi {
+        color: #18a7c8;;        
+        font-weight: bold;
+    }
+
+    .opr {
+        color: yellow;        
+    }
+
+    .str {
+        color: red;        
+        font-weight: bold;   
+    }
+/;
+
+
+1;
\ No newline at end of file
index ddd53fb14656d1643916c0f030116bf9b8654724..100da6ef0ad142b2183612cc1f96f9d0b7be3f98 100644 (file)
@@ -169,13 +169,13 @@ try{
     foreach my $ln(split(/\n/,$script)){        
            $ln =~ s/\t/$TAB/gs; $lnc++;
         if($ln =~ /^```(\w*)\s(.*)```$/g){
-            $tag = $1;
-            $ln  = $2;
+            $tag = $1; 
+            $ln  = $2; $list_end=0;
             my @code_tag = @{ setCodeTag($tag, "") }; 
             $buff .= qq(<$code_tag[1] class='$code_tag[0]'>$ln</$code_tag[1]>\n);
             next
         }elsif($ln =~ /^\s*```(\w*)/){
-            my $bfCode;
+            my $bfCode; 
             if(!$tag){
                 my @code_tag = @{ setCodeTag($1, $1) };
                 $class = $code_tag[0];         
@@ -231,8 +231,7 @@ try{
             }elsif($spc>$nplen){
                 $list_item -> add($new);                
                 $list_item = $new;
-                $nplen = $spc;
-                $list_end = 0;
+                $nplen = $spc;                
             }else{   
                my $isEq = $list_item->{spc} == $spc;             
                while($list_item->{spc} >= $spc && $list_item -> parent()){                     
@@ -243,6 +242,7 @@ try{
                $list_item -> add($new);
                $list_item = $new;               
             }            
+            $list_end = 0;
         }elsif(!$code && $ln =~ /(^|\\G)[ ]{0,3}(>+) ?/){
             my $nested = length($2);
              $ln =~ s/^\s*\>+//;
@@ -283,22 +283,21 @@ try{
                 $buff .= qq(<hr>\n)
             }
         }
-        elsif($ln =~ /^\s*(.*)/ && length($1)>0){
+        elsif($ln =~ /^(\s*)(.*)/ && length($2)>0){
             if($code){
-                 my $v=$1;
+                 my $v=$2; my $spc=$1; $list_end =0;
                 if($tag eq 'pre' && $code == 1){
                     $v =~ s/</&#60;/g;
                     $v =~ s/>/&#62;/g;
                     $para .= "$v\n"; 
                 }elsif($code == 2){
                     if($ln =~/^\s*\<+.*>+$/){
-                       $para .= inlineCNF($v)."<br>\n"
-                                        
+                       $para .= inlineCNF($v,$spc)."<br>\n"                                        
                     }else{
                        $para .= code2HTML($v)."<br>\n"
                     }
                 }else{           
-                    $v = inlineCNF($v);
+                    $v = inlineCNF($v,$spc);
                     if(length($v) > length($ln)){
                        $para .= qq($v<br>);
                        next
@@ -383,7 +382,7 @@ try{
                     $para   .= $bqte;
                     undef $bqte;
                 }
-                $para .= ${style($1)}."\n"         
+                $para .= ${style($2)}."\n"         
             }
         }else{
             if($list_root && ++$list_end>1){
@@ -424,7 +423,7 @@ sub code2HTML($val){
     }       
     
     $v =~ s/([,;=\-\+]+)/<span class='opr'>$1<\/span>/gx;
-    $v =~ s/(my|our|local|use|lib|require|new|while|for|foreach|while|if|else|elsif|eval)/<span class='kw'>$1<\/span>/g;        
+    $v =~ s/(my|our|local|do|use|lib|require|new|while|for|foreach|while|if|else|elsif|eval)/<span class='kw'>$1<\/span>/g;        
     $v =~ s/(\$\w+)/<span class='var'>$1<\/span>/g;
     $v =~ s/([\(\)\{\}\[\]] | ->)/<span class='bra'>$1<\/span>/gx;
     foreach(0..$#strs){
@@ -437,37 +436,91 @@ sub code2HTML($val){
         return $v
 }
 
-sub inlineCNF($v){
-
+sub inlineCNF($v,$spc){
+ $spc =~ s/\s/&nbsp;/g;
  $v =~ m/ (<{2,3})(.*?)(>{2,3}) (.*)   /gmx;
  my $oo = $1;
  my $body = $2;
  my $cc = $3;
- my $restIfAny = $4;
- return $v if !$1 || !$2 || !$3;
+ my $restIfAny = $4; $restIfAny="" if not $restIfAny;
 
-    $oo =~ s/</&#60;/g;        
+if (!$body){
+    $oo=$cc="";  $body=$v;$v=~/^(<+)/;$oo=$1 if$1;
+    if($v=~m/\[\#\[/){
+        return "$spc<span ".C_PV.">[#[</span>"
+    }
+    elsif($v=~m/\]\#\]/){
+        return "$spc<span ".C_PV.">]#]</span>"
+    }
+    elsif($v=~m/^\[(\w*)\[/ && $1){
+       return "$spc<span ".C_B.">[</span><span ".C_PI.">$1</span><span ".C_B.">[</span>"
+    }
+    elsif($v=~m/\](\w*)\]/ && $1){
+       return "$spc<span ".C_B.">]</span><span ".C_PI.">$1</span><span ".C_B.">]</span>"
+    }
+    elsif($v=~m/^<{1}(\w*)<{1}/ && $1){
+       return "$spc<span ".C_B.">&#60;</span><span ".C_PV.">$1</span><span ".C_B.">&#60;</span>"
+    }elsif($v=~m/^>{1}(\w*)>{1}/ && $1){
+       return "$spc<span ".C_B.">&#62;</span><span ".C_PV.">$1</span><span ".C_B.">&#62;</span>"
+    }elsif($v=~m/^<\*<.*>\*>$/){
+        my $r = "<span ".C_B.">&#62;</span><span ".C_PV.">*</span><span ".C_B.">&#62;</span>"; 
+        $body=~s/>\*>$/$r/;
+           $r = "<span ".C_B.">&#60;</span><span ".C_PV.">*</span><span ".C_B.">&#60;</span>"; 
+        $body=~s/^<\*</$r/;
+        return $spc.$body
+    }
+    elsif($v eq '>>'){
+        return  "$spc<span ".C_B.">&#62;&#62;</span>\n"  }
+    else{
+        $v=~/(>+)$/;if($1){
+        $cc=$1;
+         #$body =~ s/>/&#62;/g;  
+        }else{
+            $oo =~ s/</&#60;/g;
+            if($v=~m/<<<(.*)/){
+              return "<span ".C_B.">$oo</span><span ".C_PI.">$1</span>"
+            }elsif($v=~m/^(<{2,3})(.*?)([><])(.*)/){                
+              return "$spc<span ".C_B.">$oo</span><span ".C_PN.">$1</span>><span ".C_B.">$2</span><span ".C_PI.">$3</span>";                
+            }else{
+              return propValCNF($v)
+            }
+        }
+    }
+}
+    $oo =~ s/</&#60;/g;
     $cc =~ s/>/&#62;/g;     
-
     $body =~ m/ ([@%]<)  ([\$@%]?\w+) ([<>])  |                  
                 ([^<>]+) ([><])? (.*)
             /gmx;
 
     if($4&&$5&&$6){
         my ($o,$var,$val, $prop);
-        $var  = $4; $o=$5; $val=$6;         
-        if($PARSER->isReservedWord($var)){
-                $var = "<span ".C_PI.">$var</span>"
+        $var  = $4; $o=$5; $val=$6;   
+        $val  =~ /(.*)(>$)/; if($1&&$2){
+            my $v = $1;
+            my $i = $2;
+            if($PARSER->isReservedWord($v)){
+               $v = "<span ".C_PI.">$v</span>"
+            }else{
+               $v =~ s/(\w+)(\$+)/<span class='pa'>$1<\/span><span class='ps'">$2<\/span>/g;
+               $v = "<span ".C_PA.">$i</span>" if !$2;
+            }
+            $val=$v; $cc = "<span ".C_B.">&#62;</span>";
+
+        }elsif($PARSER->isReservedWord($var)){
+                $var = "<span ".C_PI.">$var</span>";
+                $val =~ s/</&#60;/g;
+                $val =~ s/>/&#62;/g;
         }else{
                 $var =~ s/(\w+)(\$+)/<span class='pa'>$1<\/span><span class='ps'">$2<\/span>/g;
                 $var = "<span ".C_PA.">$var</span>" if !$2;
+                $val =~ s/</&#60;/g;
+                $val =~ s/>/&#62;/g;
         }
         my $r = "<span ".C_B.">&#60;</span>";
         $o =~ s/^</$r/ge;
         $r = "<span ".C_B.">&#62;</span>";
         $o =~ s/^>/$r/ge;
-        $val =~ s/</&#60;/g;
-        $val =~ s/>/&#62;/g;
 
         $prop = "$var</span>$o<span ".C_PV.">$val</span>";
 
@@ -498,16 +551,16 @@ sub inlineCNF($v){
         my $prop = propValCNF($3);
         $v = "<span ".C_B.">$oo</span>$ins<\/span>$prop<span ".C_B.">$cc</span>"
     }
-    return $v.$restIfAny
+    return $spc.$v.$restIfAny
 }
 
 
 sub propValCNF($v){    
     $v =~ m/(.*)([=:])(.*)/gs;
     if($1&&$2&&$3){
-       $v = "&nbsp;<span ".C_PN.">$1</span><span class='O'>$2</span><span ".C_PV.">$3</span>";
+      return "&nbsp;<span ".C_PN.">$1</span><span class='O'>$2</span><span ".C_PV.">$3</span>";
     }else{
-       $v = "&nbsp;<span ".C_PV.">$v</span>";
+       return "&nbsp;<span ".C_PV.">$v</span>";
     }
     return $v;
 }
@@ -524,7 +577,7 @@ sub style ($script){
     #Inline code
     $ret =~ m/```(.*)```/g;
     if($1){
-        my $v = inlineCNF($1);        
+        my $v = inlineCNF($1,"");
         $ret =~ s/```(.*)```/\<span\>$v<\/span\>/;         
     }
     
index 3b954f8bbbd40ecff7e291e6daf527abcb0b668a..de935ba43ae8582d3a31e88c8772bdc2e89293bb 100644 (file)
@@ -51,32 +51,34 @@ use constant META => '^CONFIG_META';
 
 
 # DEFAULT SETTINGS HERE! These settings kick in if not found in config file. i.e. wrong config file or has been altered, things got missing.
-our $RELEASE_VER  = '2.5';
-our $TIME_ZONE    = 'Australia/Sydney';
-our $LANGUAGE     = 'English';
-our $PRC_WIDTH    = '60';
-our $LOG_PATH     = '../../dbLifeLog/';
-our $SESSN_EXPR   = '+30m';
-our $DATE_UNI     = '0';
-our $AUTHORITY    = '';
-our $IMG_W_H      = '210x120';
-our $REC_LIMIT    = 25;
-our $AUTO_WRD_LMT = 1000;
-our $AUTO_WRD_LEN = 17; #Autocompletion word length limit. Internal.
-our $AUTO_LOGOFF  = 0;
-our $VIEW_ALL_LMT = 1000;
-our $DISP_ALL     = 1;
-our $FRAME_SIZE   = 0;
-our $RTF_SIZE     = 0;
-our $THEME        = 'Standard';
-our $TRANSPARENCY = 1;
-our $TRANSIMAGE   = 'wsrc/images/std-log-lbl-bck.png';
-our $TRACK_LOGINS = 1;
-our $KEEP_EXCS    = 0;
-our $COMPRESS_ENC = 0; #HTTP Compressed encoding.
-our $DBI_SOURCE   = "DBI:SQLite:";
-our $DBI_LVAR_SZ  = 1024;
-our $CURR_SYMBOL  = '&#36;';#'$';
+our $RELEASE_VER   = '2.5';
+our $TIME_ZONE     = 'Australia/Sydney';
+our $LANGUAGE      = 'English';
+our $PRC_WIDTH     = '60';
+our $LOG_PATH      = '../../dbLifeLog/';
+our $SESSN_EXPR    = '+30m';
+our $DATE_UNI      = '0';
+our $AUTHORITY     = '';
+our $IMG_W_H       = '210x120';
+our $REC_LIMIT     = 25;
+our $AUTO_WRD_LMT  = 1000;
+our $AUTO_WRD_LEN  = 17;           #Autocompletion word length limit. Internal.
+our $AUTO_LOGOFF   = 0;
+our $AUDIO_ENABLED = 1;
+our $VIEW_ALL_LMT  = 1000;
+our $DISP_ALL      = 1;
+our $FRAME_SIZE    = 0;
+our $RTF_SIZE      = 0;
+our $THEME         = 'Standard';
+our $TRANSPARENCY  = 1;
+our $TRANSIMAGE    = 'wsrc/images/std-log-lbl-bck.png';
+our $TRACK_LOGINS  = 1;
+our $KEEP_EXCS     = 0;
+our $COMPRESS_ENC  = 0;                                #HTTP Compressed encoding.
+our $DBI_SOURCE    = "DBI:SQLite:";
+our $DBI_LVAR_SZ   = 1024;
+our $CURR_SYMBOL   = '&#36;';
+
 
 my ($cgi, $sss, $sid, $alias, $pass, $dbname, $pub);
 our $DSN;
@@ -127,6 +129,7 @@ sub recordLimit    {$REC_LIMIT}
 sub autoWordLimit  {$AUTO_WRD_LMT}
 sub autoWordLength {$AUTO_WRD_LEN}
 sub autoLogoff     {$AUTO_LOGOFF}
+sub audioEnabled   {$AUDIO_ENABLED}
 sub viewAllLimit   {$VIEW_ALL_LMT}
 sub displayAll     {$DISP_ALL}
 sub trackLogins    {$TRACK_LOGINS}
@@ -436,30 +439,31 @@ sub getConfiguration { my ($db, $hsh) = @_;
         my $st = $db->prepare("SELECT ID, NAME, VALUE FROM CONFIG;");  $st->execute();
         while ( @r = $st->fetchrow_array() ){
                 given ( $r[1] ) {
-                when ("RELEASE_VER") {$RELEASE_VER  = $r[2]}
-                when ("TIME_ZONE")   {$TIME_ZONE    = $r[2]}
-                when ("PRC_WIDTH")   {$PRC_WIDTH    = $r[2]}
-                when ("SESSN_EXPR")  {$SESSN_EXPR   = timeFormatSessionValue($r[2])}
-                when ("DATE_UNI")    {$DATE_UNI     = $r[2]}
-                when ("LANGUAGE")    {$LANGUAGE     = $r[2]}
-                when ("LOG_PATH")    {} # Ommited and code static can't change for now.
-                when ("IMG_W_H")     {$IMG_W_H      = $r[2]}
-                when ("REC_LIMIT")   {$REC_LIMIT    = $r[2]}
-                when ("AUTO_WRD_LMT"){$AUTO_WRD_LMT = $r[2]}
-                when ("AUTO_LOGOFF") {$AUTO_LOGOFF  = $r[2]}
-                when ("VIEW_ALL_LMT"){$VIEW_ALL_LMT = $r[2]}
-                when ("DISP_ALL")    {$DISP_ALL     = $r[2]}
-                when ("FRAME_SIZE")  {$FRAME_SIZE   = $r[2]}
-                when ("RTF_SIZE")    {$RTF_SIZE     = $r[2]}
-                when ("THEME")       {$THEME        = $r[2]}
-                when ("TRANSPARENCY"){$TRANSPARENCY = $r[2]}
-                when ("TRANSIMAGE")  {$TRANSIMAGE   = $r[2]}
-                when ("DEBUG")       {$DEBUG        = $r[2]}
-                when ("KEEP_EXCS")   {$KEEP_EXCS    = $r[2]}
-                when ("TRACK_LOGINS"){$TRACK_LOGINS = $r[2]}
-                when ("COMPRESS_ENC"){$COMPRESS_ENC = $r[2]}
-                when ("CURR_SYMBOL") {$CURR_SYMBOL  = $r[2]}
-                default              {$anons{$r[1]} = $r[2]}
+                when ("RELEASE_VER") { $RELEASE_VER = $r[2] }
+                when ("TIME_ZONE")   { $TIME_ZONE   = $r[2] }
+                when ("PRC_WIDTH")   { $PRC_WIDTH   = $r[2] }
+                when ("SESSN_EXPR") {  $SESSN_EXPR = timeFormatSessionValue( $r[2] ) }
+                when ("DATE_UNI") { $DATE_UNI = $r[2] }
+                when ("LANGUAGE") { $LANGUAGE = $r[2] }
+                when ("LOG_PATH") {}    # Ommited and code static can't change for now.
+                when ("IMG_W_H")       { $IMG_W_H        = $r[2] }
+                when ("REC_LIMIT")     { $REC_LIMIT      = $r[2] }
+                when ("AUTO_WRD_LMT")  { $AUTO_WRD_LMT   = $r[2] }
+                when ("AUTO_LOGOFF")   { $AUTO_LOGOFF    = $r[2] }
+                when ("AUDIO_ENABLED") { $AUDIO_ENABLED  = $r[2] }
+                when ("VIEW_ALL_LMT")  { $VIEW_ALL_LMT   = $r[2] }
+                when ("DISP_ALL")      { $DISP_ALL       = $r[2] }
+                when ("FRAME_SIZE")    { $FRAME_SIZE     = $r[2] }
+                when ("RTF_SIZE")      { $RTF_SIZE       = $r[2] }
+                when ("THEME")         { $THEME          = $r[2] }
+                when ("TRANSPARENCY")  { $TRANSPARENCY   = $r[2] }
+                when ("TRANSIMAGE")    { $TRANSIMAGE     = $r[2] }
+                when ("DEBUG")         { $DEBUG          = $r[2] }
+                when ("KEEP_EXCS")     { $KEEP_EXCS      = $r[2] }
+                when ("TRACK_LOGINS")  { $TRACK_LOGINS   = $r[2] }
+                when ("COMPRESS_ENC")  { $COMPRESS_ENC   = $r[2] }
+                when ("CURR_SYMBOL")   { $CURR_SYMBOL    = $r[2] }
+                default                { $anons{ $r[1] } = $r[2] }
                 }
         }
         #Anons are murky grounds. -- @bud