From c7f6d9bac31b4c840f98835d1763e89621959051 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Fri, 21 Apr 2017 18:37:28 +0200
Subject: [PATCH] Improved doxygen

I added a primitive syntax highlighter for plumed examples.
It links to manual as well.
---
 user-doc/Doxyfile          | 10 +++++--
 user-doc/go-doxygen        |  4 +--
 user-doc/plumed-syntax.awk | 54 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 4 deletions(-)
 create mode 100755 user-doc/plumed-syntax.awk

diff --git a/user-doc/Doxyfile b/user-doc/Doxyfile
index fdcd5c477..7a884face 100644
--- a/user-doc/Doxyfile
+++ b/user-doc/Doxyfile
@@ -228,11 +228,17 @@ TAB_SIZE               = 8
 # "Side Effects:". You can put \n's in the value part of an alias to insert
 # newlines.
 
-ALIASES                = "hidden=\htmlonly <details> <summary> <b> To learn more </b> </summary> <div class=\"hidden\"> \endhtmlonly" \
+ALIASES                = \
+                         "hidden=\htmlonly <details> <summary> <b> To learn more </b> </summary> <div class=\"hidden\"> \endhtmlonly" \
                          "hidden{1}=\htmlonly <details> <summary> <b> To learn more: \1 </b> </summary> <div class=\"hidden\"> \endhtmlonly" \
                          "endhidden=\htmlonly </div> </details> \endhtmlonly" \
                          "issue{1}=<a href=\"http://github.com/plumed/plumed2/issues/\1\">#\1</a>" \
-                         "branch{1}=<a href=\"http://github.com/plumed/plumed2/commits/\1\">\1</a>"
+                         "branch{1}=<a href=\"http://github.com/plumed/plumed2/commits/\1\">\1</a>" \
+                         "highlight{1}=\htmlonly<span style=\"background-color:yellow\">\endhtmlonly\1\htmlonly</span>\endhtmlonly" \
+                         "tarball{1}=<a href=\"tutorial-resources/\1.tar.gz\" style=\"font-weight:bold\" style=\"color:green\" download=\"\1.tar.gz\"> TARBALL </a>" \
+                         "plumedfile=\verbatim BEGIN_PLUMED_FILE" \
+                         "endplumedfile=\endverbatim"
+
 
 # This tag can be used to specify a number of word-keyword mappings (TCL only).
 # A mapping has the form "name=value". For example adding "class=itcl::class"
diff --git a/user-doc/go-doxygen b/user-doc/go-doxygen
index aff6debd1..a3d87e201 100755
--- a/user-doc/go-doxygen
+++ b/user-doc/go-doxygen
@@ -36,7 +36,8 @@ awk -v version="$version" '{
     print "      <li><a href=\"tutorials.html\"><span>Tutorials</span></a></li>"
     print "      <li><a href=\"glossary.html\"><span>Index&#160;of&#160;Actions</span></a></li>"
   } else print
-}' $file > $file.tmp
+}' $file |
+awk -f plumed-syntax.awk > $file.tmp
 mv $file.tmp $file
 done
 # end of DOXYGEN <=1.8.10
@@ -51,7 +52,6 @@ var menudata={children:[
 EOF
 # end of DOXYGEN >=1.8.12
 
-
 cat html/doxygen.css plumed.css > html/doxygen.css.tmp
 mv html/doxygen.css.tmp html/doxygen.css
 
diff --git a/user-doc/plumed-syntax.awk b/user-doc/plumed-syntax.awk
new file mode 100755
index 000000000..7d261bca4
--- /dev/null
+++ b/user-doc/plumed-syntax.awk
@@ -0,0 +1,54 @@
+{
+  if(match($0,"BEGIN_PLUMED_FILE")){
+    inside=1;
+    sub("BEGIN_PLUMED_FILE","");
+    print;
+    next;
+  }
+  if(inside && match($0,"</pre>")){
+    inside=0;
+    print;
+    next;
+  }
+  if(!inside){
+    print;
+    next;
+  }
+
+# DRAFT LINK TO DOC:
+ copy=$0
+ sub("#.*","",copy);
+ nw=split(copy,words);
+ if(match(words[1],".*:$")){
+   action=words[2];
+ } else {
+   action=words[1];
+ }
+ if(action=="__FILL__") action=""
+ actionx="";
+ for(i=1;i<=length(action);i++){
+   letter=substr(action,i,1);
+   if(match(letter,"[A-Z]")) letter = "_" tolower(letter);
+   actionx=actionx letter;
+ }
+ if(incontinuation) action="";
+ if(incontinuation && words[1]=="...") incontinuation=0;
+ else if(!incontinuation && words[nw]=="...") incontinuation=1;
+
+ if(length(action)>0){
+   actionfile="html/" actionx ".html";
+   if(getline tmp < actionfile < 0) print "WARNING: file " actionfile " does not exist" > "/dev/stderr";
+   else {
+     p=match($0,action);
+     $0=substr($0,1,p-1) "<a href=\"./" actionx ".html\" style=\"color:green\">" action "</a>" substr($0,p+length(action));
+   }
+ }
+
+ gsub("__FILL__","<span style=\"background-color:yellow\">__FILL__</span>");
+
+# comments:
+#  sub("#","<span style=\"color:blue\">#");
+#  if(match($0,"span style=")) $0=$0 "</span>";
+  sub("#.*$","<span style=\"color:blue\">&</span>");
+  print
+}
-- 
GitLab