]> git.proxmox.com Git - pve-docs.git/commitdiff
mediawiki: load JS helper in plugin instead of including it in the html out
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 28 May 2021 14:03:59 +0000 (16:03 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 28 May 2021 14:03:59 +0000 (16:03 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
asciidoc/mediawiki-asciidoc.js [deleted file]
asciidoc/mediawiki.conf
debian/tree/pve-docs-mediawiki/PVEDocs/include/PVEDocs.php
debian/tree/pve-docs-mediawiki/PVEDocs/mw-asciidoc.js [new file with mode: 0644]

diff --git a/asciidoc/mediawiki-asciidoc.js b/asciidoc/mediawiki-asciidoc.js
deleted file mode 100644 (file)
index 655f3f7..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-//////////////////////////////////////////////////////////////////////////
-// asciidoc JS helper for Proxmox VE mediawiki pages
-//
-// code based on original asciidoc.js, but re-written using jQuery
-//
-//////////////////////////////////////////////////////////////////////////
-
-var asciidoc = {
-    toc: function ($content) { // toc generator
-       var tocholder = $content.find('#toc');
-       if (!tocholder) {
-           return;
-       }
-       tocholder.html('');
-       tocholder.hide();
-
-       var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
-
-       var n = 0;
-       $content.find("div.sect1").each(function(){
-           var h = jQuery(this).find("h2").first();
-           var id = h.attr("id");
-           if (id != null) {
-               n++;
-               html += "<li class=\"toclevel-1\">" +
-                   "<a href=\"#" + id + "\">" +
-                   "<span class=\"toctext\">" + h.html() +
-                   "</span></a></li>";
-           }
-       });
-
-       html += "</ul>";
-
-       if (n > 3) {
-           tocholder.html(html);
-           tocholder.show();
-       }
-    },
-
-    // footnote generator
-    footnotes: function ($content) {
-       var noteholder = $content.find('#footnotes');
-       if (!noteholder) {
-           return;
-       }
-
-       noteholder.html('');
-
-       // Rebuild footnote entries.
-       var refs = {};
-       var n = 0;
-       var inner_html = '';
-
-       $content.find("span.footnote").each(function(){
-           n++;
-           var span = jQuery(this);
-           var note = span.attr("data-note");
-           var id = span.attr("id");
-           if (!note) {
-               // Use [\s\S] in place of . so multi-line matches work.
-               // Because JavaScript has no s (dotall) regex flag.
-               note = span.html().match(/\s*\[([\s\S]*)]\s*/)[1];
-               span.html("[<a id='_footnoteref_" + n + "' href='#_footnote_" +
-                         n + "' title='View footnote' class='footnote'>" + n +
-                         "</a>]");
-               span.attr("data-note", note);
-           }
-           inner_html +=
-            "<div class='footnote' id='_footnote_" + n + "'>" +
-               "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
-               n + "</a>. " + note + "</div>";
-
-           if (id != null) { refs["#"+id] = n; }
-       });
-
-       if (inner_html) { noteholder.html("<hr>" + inner_html); }
-
-       if (n != 0) {
-           // process footnoterefs.
-           $content.find("span.footnoteref").each(function(){
-               var span = jQuery(this);
-               var href = span.find("a").first().attr("href");
-               href = href.match(/#.*/)[0];  // in case it return full URL.
-               n = refs[href];
-               span.html("[<a href='#_footnote_" + n +
-                         "' title='View footnote' class='footnote'>" + n + "</a>]");
-           });
-       }
-    }
-};
-
-// add init to mediawiki resource loader queue
-(window.RLQ=window.RLQ||[]).push(function(){
-    // cannot use mw.hook directly here yet, the mediawiki.base module is not yet available
-    mw.loader.implement('pve.doctoc', function() {
-       mw.hook('wikipage.content').add(function($content) {
-           asciidoc.toc($content);
-           asciidoc.footnotes($content);
-       });
-    });
-});
index 201b081b34885ad9dde0d3f3a665ef34473b6273..e7e15d47b0005bbab275268a70aa84e95950aaf3 100644 (file)
@@ -540,10 +540,6 @@ bodydata=<td class="tableblock halign-{colalign=left}">|</td>
 </div>
 
 [header]
-<!-- asciidoc HEADER -->
-<script type="text/javascript">
-include1::mediawiki-asciidoc.js[]
-</script>
 template::[toc]
 <div id="asciidoccontent">
 <style type="text/css" scoped>
index b7acb34b930a1923573beaee57225af0efb346f6..23cbb50ffeb50f462a5e98d7515f35d854e7d6bf 100644 (file)
@@ -34,7 +34,10 @@ class PVEDocs {
             die("no such manual page");
         }
 
-        $content = file_get_contents("/usr/share/pve-docs/$doc");
+        // load JS helper for TOC/footnote generation and load actual HTML content fom docs
+        $content = "\n<script type=\"text/javascript\">\n".file_get_contents("/usr/lib/pve-docs/PVEDocs/mw-asciidoc.js") ."</script>";
+
+        $content .= file_get_contents("/usr/share/pve-docs/$doc");
 
         // from https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/HTMLets/+/11e5ef1ea2820319458dc67174ca76d6e00b10cc/HTMLets.php#140
         $output = '<!--- @PVEDOCS_BASE64@ '.base64_encode($content).' @PVEDOCS_BASE64@ -->';
diff --git a/debian/tree/pve-docs-mediawiki/PVEDocs/mw-asciidoc.js b/debian/tree/pve-docs-mediawiki/PVEDocs/mw-asciidoc.js
new file mode 100644 (file)
index 0000000..655f3f7
--- /dev/null
@@ -0,0 +1,101 @@
+//////////////////////////////////////////////////////////////////////////
+// asciidoc JS helper for Proxmox VE mediawiki pages
+//
+// code based on original asciidoc.js, but re-written using jQuery
+//
+//////////////////////////////////////////////////////////////////////////
+
+var asciidoc = {
+    toc: function ($content) { // toc generator
+       var tocholder = $content.find('#toc');
+       if (!tocholder) {
+           return;
+       }
+       tocholder.html('');
+       tocholder.hide();
+
+       var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
+
+       var n = 0;
+       $content.find("div.sect1").each(function(){
+           var h = jQuery(this).find("h2").first();
+           var id = h.attr("id");
+           if (id != null) {
+               n++;
+               html += "<li class=\"toclevel-1\">" +
+                   "<a href=\"#" + id + "\">" +
+                   "<span class=\"toctext\">" + h.html() +
+                   "</span></a></li>";
+           }
+       });
+
+       html += "</ul>";
+
+       if (n > 3) {
+           tocholder.html(html);
+           tocholder.show();
+       }
+    },
+
+    // footnote generator
+    footnotes: function ($content) {
+       var noteholder = $content.find('#footnotes');
+       if (!noteholder) {
+           return;
+       }
+
+       noteholder.html('');
+
+       // Rebuild footnote entries.
+       var refs = {};
+       var n = 0;
+       var inner_html = '';
+
+       $content.find("span.footnote").each(function(){
+           n++;
+           var span = jQuery(this);
+           var note = span.attr("data-note");
+           var id = span.attr("id");
+           if (!note) {
+               // Use [\s\S] in place of . so multi-line matches work.
+               // Because JavaScript has no s (dotall) regex flag.
+               note = span.html().match(/\s*\[([\s\S]*)]\s*/)[1];
+               span.html("[<a id='_footnoteref_" + n + "' href='#_footnote_" +
+                         n + "' title='View footnote' class='footnote'>" + n +
+                         "</a>]");
+               span.attr("data-note", note);
+           }
+           inner_html +=
+            "<div class='footnote' id='_footnote_" + n + "'>" +
+               "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
+               n + "</a>. " + note + "</div>";
+
+           if (id != null) { refs["#"+id] = n; }
+       });
+
+       if (inner_html) { noteholder.html("<hr>" + inner_html); }
+
+       if (n != 0) {
+           // process footnoterefs.
+           $content.find("span.footnoteref").each(function(){
+               var span = jQuery(this);
+               var href = span.find("a").first().attr("href");
+               href = href.match(/#.*/)[0];  // in case it return full URL.
+               n = refs[href];
+               span.html("[<a href='#_footnote_" + n +
+                         "' title='View footnote' class='footnote'>" + n + "</a>]");
+           });
+       }
+    }
+};
+
+// add init to mediawiki resource loader queue
+(window.RLQ=window.RLQ||[]).push(function(){
+    // cannot use mw.hook directly here yet, the mediawiki.base module is not yet available
+    mw.loader.implement('pve.doctoc', function() {
+       mw.hook('wikipage.content').add(function($content) {
+           asciidoc.toc($content);
+           asciidoc.footnotes($content);
+       });
+    });
+});