diff --git a/scripts/docs/update_web_vep_plugins_documentation.pl b/scripts/docs/update_web_vep_plugins_documentation.pl index 77ef3eb0d..ab7233a1a 100644 --- a/scripts/docs/update_web_vep_plugins_documentation.pl +++ b/scripts/docs/update_web_vep_plugins_documentation.pl @@ -141,12 +141,12 @@ =head1 CONTACT # Print output HTML open OUT, "> $output_file" or die $!; -my $table_content .= qq{ - +my $table_content .= qq{ +
- + @@ -170,13 +170,14 @@ =head1 CONTACT $plugin_class_list{$plugin_class} = $plugin_id; $table_content .= sprintf( - ''. + ''. ''. ''. - ''. + ''. ''. ''. '', + $plugin_name, $tr_class, $plugin_id, "$vep_plugin_url_version/$file", @@ -230,6 +231,7 @@ sub read_plugin_file { my @developer = (); my $name = ''; my $desc = ''; + my $usage = ''; my %libs; open F, "< $git_dir/$file" or die $!; @@ -286,44 +288,124 @@ sub read_plugin_file { } } } - + + # Get plugin synopsis (usage examples) + if ($line =~ /=head1 SYNOPSIS/) { + my $synopsis_flag = 1; + while ($synopsis_flag != 0) { + $line = ; + if ($line =~ /^\s*=head1/ || $line =~ /^\s*=cut/) { + $synopsis_flag = 0; + } else { + $line =~ s/^\h+//; + $usage .= $line; + } + } + chomp($usage); + $usage = '

Usage examples:

' . $usage . '
'; + } + # Get the plugin description if ($line =~ /=head1 DESCRIPTION/) { my $desc_flag = 1; my $code_block = 0; my $code_script = 0; - my $cmds = join "|", qw( zcat zgrep cat wget rm gzip gunzip awk head - sort sed bgzip unzip cd perl make tabix mysql - echo tar ./filter_vep ./vep ); + + my $ulist = 0; + my $ulist_newline = 0; # prepare to ignore newlines + my $olist = 0; + my $olist_newline = 0; # prepare to ignore newlines + + my $table = 0; + my $table_newline = 0; # prepare to ignore newlines + my $tr_class = ''; + + my $cmds = join "|", qw( ./vep ./filter_vep awk bgzip cat cd chmod cp curl + echo exit grep gunzip gzip head ls less make mkdir + mysql mv perl rm sed sort paste pwd sudo tabix + tail tar touch unzip wget zcat zgrep zip ); $cmds =~ s#(\.|/)#\\$1#g; while ($desc_flag != 0) { $line = ; + # Escape non-HTML tags, such as + $line =~ s|<|<|g; + $line =~ s|>|>|g; + if ($line =~ /^\s*=head1/ || $line =~ /^\s*=cut/) { $desc_flag = 0; } else { if ($desc ne '' || $line !~ /^\s+$/) { + # Create unordered list when starting line with certain characters + if ($line =~ /^\s*[-*+] (.*)/) { + $line = ($ulist ? '' : '
    ') . '
  • ' . $1; + $ulist = 1; + $ulist_newline = 0; + } elsif ($ulist) { + if ($ulist_newline) { + $line = '

' . $line; + $ulist = 0; + } elsif ($line =~ '^\s+$') { + $ulist_newline = 1; + } else { + $line = ' ' . $line; + } + } + + # Create table for plugin arguments + if ($line =~ 'key=value') { + $line = '

PluginDescriptionDescription Category External libraries Developer
%s
%s
%s
%s
%s
%s%s

' . $line if $table; + $table = 1; + $table_newline = 0; + chomp($line); + $line .= + ''. + ''. + ''; + } elsif ($table) { + if ($line =~ ' : ') { + my ($arg, $description) = split(/ : /, $line); + $arg =~ s/^\s+|\s+$//g; + $description =~ s/^\s+|\s+$//g; + $tr_class = ($tr_class eq 'bg1') ? 'bg2' : 'bg1'; + $line = join("", + '', + '', + '
ArgumentDescription
' . $arg . '
' . $description . ' '); + $table_newline = 0; + } elsif ($table_newline) { + $line = '

' . $line; + $table = 0; + $table_newline = 0; + } elsif ($line =~ '^\s+$') { + $table_newline = 1; + } + } + # Add code block -- three types of code blocks: # 1. to show a code script - # start: line starts with ##### or contains # BEGIN - # end: line contains # END + # start: line contains # BEGIN or starts with ``` or ##### + # end: line contains # END or starts with ``` # 2. to show arbitrary code lines # line starts with > or --plugin or bash commands (see $cmds) # 3. to illustrate variant location: # start: line contains v (variant) after 3 or more spaces # end: line only contains I (intron) or ES/EE (exon start/end) - if ($line =~ /#{5,}/ || $line =~ /# BEGIN/) { - # start block of code script - $line = '

' . $line unless $code_script;
-              $code_script = 1;
-            } elsif ($code_script) {
-              # continue code script until getting to a line containing # END
-              if ($line =~ /# END/) {
+            if ($code_script) {
+              # continue code script until getting to a line containing # END or ```
+              $line =~ s/^\s*>?\s?//;
+              if ($line =~ /# END/ || $line =~ /^\s*```\s*$/) {
+                $line = '' if $line =~ /^\s*```\s*$/;
                 $line .= '
'; $code_script = 0; } + } elsif ($line =~ /#{5,}/ || $line =~ /# BEGIN/ || $line =~ /^\s*```\s*$/) { + # start block of code script + $line = '' if $line =~ /^\s*```\s*$/; + $line = '
' . $line unless $code_script;
+              $code_script = 1;
             } elsif ($line =~ /^\s{3,}v/) {
               # start code block to illustrate variant position
               $line = '
' . $line unless $code_block;
@@ -332,30 +414,50 @@ sub read_plugin_file {
               # end code block to illustrate variant position
               $line .= '
'; $code_block = 0; - } elsif ($line =~ /^\s*>\s?/ || $line =~ /^\s*($cmds)\s/ || $line =~ /^\s*--plugin/) { + } elsif ($line =~ /^\s*\>\s?/ || $line =~ /^\s*($cmds)\s/ || $line =~ /^\s*--plugin/) { # start code block (terminal commands) - $line =~ s/^\s*>?\s?//; + $line =~ s/^\s*(\>)?\s?//; $line = '
' . $line unless $code_block;
               $code_block = 1;
             } else {
-              $line =~ s/^\s+// if $line =~ /\S+/;
               if ($code_block) {
                 # remove blank lines after code block (looks nicer)
                 $line = "" if $line =~ /^\s+$/;
 
                 # end code block (terminal commands)
-                $line = '
' . $line; + $line = '

' . $line; $code_block = 0; } } + + # Create ordered list from numbers at line start + if ($line =~ /^\s*\(?([0-9]+)[\)\.] (.*)/) { + $line = ($olist ? '' : '

    ') . '
  1. ' . $2; + $olist = 1; + $olist_newline = 0; + } elsif ($olist) { + if ($olist_newline) { + $line = '

' . $line; + $olist = 0; + } elsif ($line =~ '^\s+$') { + $olist_newline = 1; + } else { + $line = $line; + } + } + $desc .= $line; - $line = '' . $line if $code_block; + $line = '

' . $line if $code_block; } } chomp($line); } + $desc .= '

' if $ulist_newline; + $desc .= '

' if $olist_newline; + $desc .= '

' if $table_newline; + $desc .= '

' if $code_block; } - + # Get the non Ensembl Perl module dependencies if ($line =~ /^use\s+(.+);/) { my $lib = $1; @@ -364,24 +466,33 @@ sub read_plugin_file { $libs{$lib} = qq{$1$2}; } - } + } } + close(F); # Make URLs clickable - $desc =~ s|((http\|ftp)s?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9():]{0,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*[^\)\.,;:\s]))|$1|g; - + $desc =~ s|((http\|ftp)s?:\/\/(www\.)?[-a-zA-Z0-9\@:%._\+~#=]{1,256}\.[a-zA-Z0-9():]{0,6}\b([-a-zA-Z0-9()\@:%_\+.~#?&//=]*[^\)\.,;:\s\<]))|$1|g; + + # Convert DOI to URL + $desc =~ s|(doi:([^\s]+[A-Za-z0-9]))|$1|g; + + # Convert pair of single quotes to code + $desc =~ s|[\'\`]([\w:\-?\/_\.\|\&\,\;\=\]\[]*)[\'\`]|$1|g; + + # Add usage examples + $desc .= '

' . $usage . '

'; + # Postprocess the description content (reformatting) $desc = "

$desc

"; $desc =~ s/\n\s*\n/<\/p>

/g; $desc =~ s/<\/p>

<\/p>/<\/p>/g; - $desc =~ s/\n/
/g; $desc =~ s/
<\/p>/<\/p>/g; if ($desc =~ /<\/p>

/) { my $lc_name = lc($name); $lc_name =~ s/ /_/g; my $desc_link = qq{ more}; - $desc =~ s/<\/p>

/$desc_link<\/p>