]>
Commit | Line | Data |
---|---|---|
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 | // toc generator | |
11 | toc: function () { | |
12 | var tocholder = $("#toc"); | |
13 | if (!tocholder) { | |
14 | return; | |
15 | } | |
16 | ||
17 | tocholder.html(''); | |
18 | tocholder.hide(); | |
19 | ||
20 | var html = "<div id=\"toctitle\"><h2>Contents</h2></div><ul>"; | |
21 | ||
22 | var n = 0; | |
23 | $("#asciidoccontent div.sect1").each(function(){ | |
24 | var h = $(this).find("h2").first(); | |
25 | var id = h.attr("id"); | |
26 | if (id != null) { | |
27 | n++; | |
28 | html += "<li class=\"toclevel-1\">" + | |
29 | "<a href=\"#" + id + "\">" + | |
30 | "<span class=\"toctext\">" + h.html() + | |
31 | "</span></a></li>"; | |
32 | } | |
33 | }); | |
34 | ||
35 | html += "</ul>"; | |
36 | ||
37 | if (n > 3) { | |
38 | tocholder.html(html); | |
39 | tocholder.show(); | |
40 | } | |
41 | }, | |
42 | ||
43 | // footnote generator | |
44 | footnotes: function () { | |
45 | var noteholder = $("#footnotes"); | |
46 | if (!noteholder) { | |
47 | return; | |
48 | } | |
49 | ||
50 | noteholder.html(''); | |
51 | ||
52 | // Rebuild footnote entries. | |
53 | var refs = {}; | |
54 | var n = 0; | |
55 | var inner_html = ''; | |
56 | ||
57 | $("#asciidoccontent span.footnote").each(function(){ | |
58 | n++; | |
59 | var span = $(this); | |
60 | var note = span.attr("data-note"); | |
61 | var id = span.attr("id"); | |
62 | if (!note) { | |
63 | // Use [\s\S] in place of . so multi-line matches work. | |
64 | // Because JavaScript has no s (dotall) regex flag. | |
65 | note = span.html().match(/\s*\[([\s\S]*)]\s*/)[1]; | |
66 | span.html("[<a id='_footnoteref_" + n + "' href='#_footnote_" + | |
67 | n + "' title='View footnote' class='footnote'>" + n + | |
68 | "</a>]"); | |
69 | span.attr("data-note", note); | |
70 | } | |
71 | inner_html += | |
72 | "<div class='footnote' id='_footnote_" + n + "'>" + | |
73 | "<a href='#_footnoteref_" + n + "' title='Return to text'>" + | |
74 | n + "</a>. " + note + "</div>"; | |
75 | ||
76 | if (id != null) { refs["#"+id] = n; } | |
77 | }); | |
78 | ||
79 | if (inner_html) { noteholder.html("<hr>" + inner_html); } | |
80 | ||
81 | if (n != 0) { | |
82 | // process footnoterefs. | |
83 | $("#asciidoccontent span.footnoteref").each(function(){ | |
84 | var span = $(this); | |
85 | var href = span.find("a").first().attr("href"); | |
86 | href = href.match(/#.*/)[0]; // in case it return full URL. | |
87 | n = refs[href]; | |
88 | span.html("[<a href='#_footnote_" + n + | |
89 | "' title='View footnote' class='footnote'>" + n + "</a>]"); | |
90 | }); | |
91 | } | |
92 | } | |
93 | }; | |
94 | ||
95 | $(document).ready(function(){ | |
96 | asciidoc.footnotes(); | |
97 | asciidoc.toc(); | |
98 | }); | |
99 |