]>
git.proxmox.com Git - pve-docs.git/blob - asciidoc/mediawiki-asciidoc.js
1 //////////////////////////////////////////////////////////////////////////
2 // asciidoc JS helper for Proxmox VE mediawiki pages
4 // code based on original asciidoc.js, but re-written using jQuery
6 //////////////////////////////////////////////////////////////////////////
9 toc: function ($content
) { // toc generator
10 var tocholder
= $content
.find('#toc');
17 var html
= "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
20 $content
.find("div.sect1").each(function(){
21 var h
= jQuery(this).find("h2").first();
22 var id
= h
.attr("id");
25 html
+= "<li class=\"toclevel-1\">" +
26 "<a href=\"#" + id
+ "\">" +
27 "<span class=\"toctext\">" + h
.html() +
41 footnotes: function ($content
) {
42 var noteholder
= $content
.find('#footnotes');
49 // Rebuild footnote entries.
54 $content
.find("span.footnote").each(function(){
56 var span
= jQuery(this);
57 var note
= span
.attr("data-note");
58 var id
= span
.attr("id");
60 // Use [\s\S] in place of . so multi-line matches work.
61 // Because JavaScript has no s (dotall) regex flag.
62 note
= span
.html().match(/\s*\[([\s\S]*)]\s*/)[1];
63 span
.html("[<a id='_footnoteref_" + n
+ "' href='#_footnote_" +
64 n
+ "' title='View footnote' class='footnote'>" + n
+
66 span
.attr("data-note", note
);
69 "<div class='footnote' id='_footnote_" + n
+ "'>" +
70 "<a href='#_footnoteref_" + n
+ "' title='Return to text'>" +
71 n
+ "</a>. " + note
+ "</div>";
73 if (id
!= null) { refs
["#"+id
] = n
; }
76 if (inner_html
) { noteholder
.html("<hr>" + inner_html
); }
79 // process footnoterefs.
80 $content
.find("span.footnoteref").each(function(){
81 var span
= jQuery(this);
82 var href
= span
.find("a").first().attr("href");
83 href
= href
.match(/#.*/)[0]; // in case it return full URL.
85 span
.html("[<a href='#_footnote_" + n
+
86 "' title='View footnote' class='footnote'>" + n
+ "</a>]");
92 // add init to mediawiki resource loader queue
93 (window
.RLQ
=window
.RLQ
||[]).push(function(){
94 // cannot use mw.hook directly here yet, the mediawiki.base module is not yet available
95 mw
.loader
.implement('pve.doctoc', function() {
96 mw
.hook('wikipage.content').add(function($content
) {
97 asciidoc
.toc($content
);
98 asciidoc
.footnotes($content
);