]> git.plutz.net Git - busy/blobdiff - templates/Wiki_show.page
improvement in wiki toc generator
[busy] / templates / Wiki_show.page
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>