]>
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 //////////////////////////////////////////////////////////////////////////
11 toc: function ($content
) {
12 var tocholder
= $content
.find('#toc');
21 var html
= "<div id=\"toctitle\"><h2>Contents</h2></div><ul>";
24 $content
.find("div.sect1").each(function(){
25 var h
= jQuery(this).find("h2").first();
26 var id
= h
.attr("id");
29 html
+= "<li class=\"toclevel-1\">" +
30 "<a href=\"#" + id
+ "\">" +
31 "<span class=\"toctext\">" + h
.html() +
45 footnotes: function ($content
) {
46 var noteholder
= $content
.find('#footnotes');
53 // Rebuild footnote entries.
58 $content
.find("span.footnote").each(function(){
60 var span
= jQuery(this);
61 var note
= span
.attr("data-note");
62 var id
= span
.attr("id");
64 // Use [\s\S] in place of . so multi-line matches work.
65 // Because JavaScript has no s (dotall) regex flag.
66 note
= span
.html().match(/\s*\[([\s\S]*)]\s*/)[1];
67 span
.html("[<a id='_footnoteref_" + n
+ "' href='#_footnote_" +
68 n
+ "' title='View footnote' class='footnote'>" + n
+
70 span
.attr("data-note", note
);
73 "<div class='footnote' id='_footnote_" + n
+ "'>" +
74 "<a href='#_footnoteref_" + n
+ "' title='Return to text'>" +
75 n
+ "</a>. " + note
+ "</div>";
77 if (id
!= null) { refs
["#"+id
] = n
; }
80 if (inner_html
) { noteholder
.html("<hr>" + inner_html
); }
83 // process footnoterefs.
84 $content
.find("span.footnoteref").each(function(){
85 var span
= jQuery(this);
86 var href
= span
.find("a").first().attr("href");
87 href
= href
.match(/#.*/)[0]; // in case it return full URL.
89 span
.html("[<a href='#_footnote_" + n
+
90 "' title='View footnote' class='footnote'>" + n
+ "</a>]");
96 // add init to mediawiki resource loader queue
97 (window
.RLQ
=window
.RLQ
||[]).push(function(){
98 mw
.hook('wikipage.content').add(function($content
) {
99 asciidoc
.toc($content
);
100 asciidoc
.footnotes($content
);