]> git.plutz.net Git - busy/commitdiff
improvement in wiki toc generator
authorpaul <paul@plutz.net>
Tue, 16 Jun 2015 15:36:23 +0000 (15:36 +0000)
committerpaul <paul@plutz.net>
Tue, 16 Jun 2015 15:36:23 +0000 (15:36 +0000)
svn path=/trunk/; revision=68

templates/Wiki.css
templates/Wiki_show.page

index 17f69be1ccc3968f698697bdcae0af3fbb09195f..af1411b8db4623be13f392c5a5ea0c6177a32c19 100644 (file)
 }
 
 .toc{ padding: 0em .5em;}
-.toc a.i0 {
+.toc a.i1 {
   font: normal bold 1em sans-serif;
   text-decoration: underline;
   margin-left: 0em;
 }
-.toc a.i1 {
+.toc a.i2 {
   font: normal bold .9em sans-serif;
   margin-left: 1em;
 }
-.toc a.i2 {
+.toc a.i3 {
   font: normal normal .8em sans-serif;
   margin-left: 2em;
 }
index d00f0e59891e47c76c70bff3de9e4b8b9428746a..fc3fd26d5fdb8b8fd49f511d01bf0a689b40e370 100755 (executable)
@@ -14,20 +14,25 @@ list_comments() {
 add_comment(){
   info="$1"
 
-  cat <<WikiEND
-      <a id='comment_button' class='function' href='#'
-         onclick='javascript:show_screen("comment");hide_screen("comment_button");'>Comment / Ask</a>
-      <div id="comment" style="display: none;">
-        <form action="./?action=wikimeta&i=$info" method="post" accept-charset="UTF-8">
-          <b>Comment:</b><br>
-          <textarea name="comm" rows="6" style="width:99%;"></textarea><br>
-          <input type="submit" value="Submit">
-          <a class="function" href="#" onclick="javascript:hide_screen('comment');show_screen('comment_button');">Cancel</a>
-        </form>
-      </div>
-WikiEND
+  cat <<-WikiEND
+       <a id='comment_button' class='function' href='#'
+          onclick='javascript:show_screen("comment");hide_screen("comment_button");'>Comment / Ask</a>
+       <div id="comment" style="display: none;">
+         <form action="./?action=wikimeta&i=$info" method="post" accept-charset="UTF-8">
+           <b>Comment:</b><br>
+           <textarea name="comm" rows="6" style="width:99%;"></textarea><br>
+           <input type="submit" value="Submit">
+           <a class="function" href="#" onclick="javascript:hide_screen('comment');show_screen('comment_button');">Cancel</a>
+         </form>
+       </div>
+       WikiEND
 }
 
+wikitext="$(_wiki Wiki/"${info}${rev}")"
+wikitoc="$(echo -E "$wikitext" \
+           | sed -rn '/<h[0-9]>.+<\/h[0-9]>/s;^.*<h([0-9])><a name="(.+)">(.+)</a></h[0-9]>.*$;<a class="i\1" href="#\2">\3</a><br>;p'
+          )"
+
 cat <<WikiEND
     <div id="LEFT">
       <form method="GET" action="./" accept-charset="utf-8">
@@ -53,22 +58,14 @@ cat <<WikiEND
         $LOGIN && echo '<hr>')
       <h1>Table of Content</h1>
       <div class="toc">
-        $(cat Wiki/"${info}${rev}" |while read line; do
-       if (egrep -q '^ *###' <<<"$line"); then
-         echo "<a class='i2' href='#$(sed 's,^ *### *,,;' <<<"$line")'>$(sed 's,^ *###,,' <<<"$line")</a><br>"
-       elif (egrep -q '^ *##' <<<"$line"); then
-         echo "<a class='i1' href='#$(sed 's,^ *## *,,;' <<<"$line")'>$(sed 's,^ *##,,' <<<"$line")</a><br>"
-       elif (egrep -q '^ *#' <<<"$line"); then
-         echo "<a class='i0' href='#$(sed 's,^ *# *,,;' <<<"$line")'>$(sed 's,^ *#,,' <<<"$line")</a><br>"
-          fi
-        done)
+        ${wikitoc}
       </div>
       <hr>
     </div>
     <div id="MAIN">
       <div class="wiki"><div class="wikitext">
         <h1 class="wikihead">$title</h1>
-        $(_wiki Wiki/"${info}${rev}")
+        ${wikitext}
       </div></div>
     </div>