]> git.proxmox.com Git - pve-docs.git/blob - asciidoc/asciidoc.js
add code to generate correct footnotes on wiki pages
[pve-docs.git] / asciidoc / asciidoc.js
1 //////////////////////////////////////////////////////////////////////////
2 // asciidoc JS helper for Proxmox VE mediawiki pages
3 //
4 // code based on original asciidoc.js, but re-written using jQuery
5 //
6 //////////////////////////////////////////////////////////////////////////
7
8 var asciidoc = {
9
10 // footnote generator
11 footnotes: function () {
12 var noteholder = $("#footnotes");
13 if (!noteholder) {
14 return;
15 }
16
17 noteholder.html('');
18
19 // Rebuild footnote entries.
20 var refs = {};
21 var n = 0;
22 var inner_html = '';
23
24 $("#asciidoccontent span.footnote").each(function(){
25 n++;
26 var span = $(this);
27 var note = span.attr("data-note");
28 var id = span.attr("id");
29 if (!note) {
30 // Use [\s\S] in place of . so multi-line matches work.
31 // Because JavaScript has no s (dotall) regex flag.
32 note = span.html().match(/\s*\[([\s\S]*)]\s*/)[1];
33 span.html("[<a id='_footnoteref_" + n + "' href='#_footnote_" +
34 n + "' title='View footnote' class='footnote'>" + n +
35 "</a>]");
36 span.attr("data-note", note);
37 }
38 inner_html +=
39 "<div class='footnote' id='_footnote_" + n + "'>" +
40 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
41 n + "</a>. " + note + "</div>";
42
43 if (id != null) { refs["#"+id] = n; }
44 });
45
46 if (inner_html) { noteholder.html("<hr>" + inner_html); }
47
48 if (n != 0) {
49 // process footnoterefs.
50 $("#asciidoccontent span.footnoteref").each(function(){
51 var span = $(this);
52 var href = span.find("a").first().attr("href");
53 href = href.match(/#.*/)[0]; // in case it return full URL.
54 n = refs[href];
55 span.html("[<a href='#_footnote_" + n +
56 "' title='View footnote' class='footnote'>" + n + "</a>]");
57 });
58 }
59 }
60 };
61
62 $(document).ready(function(){
63 asciidoc.footnotes();
64 });
65