webmcp
changeset 381:46ff54bbd10e
Anchor (URI fragment) support for autodoc system
author | jbe |
---|---|
date | Mon Nov 16 16:55:49 2015 +0100 (2015-11-16) |
parents | 16baed4c0483 |
children | 810c020b0da4 |
files | doc/autodoc-header.htmlpart framework/bin/autodoc.lua |
line diff
1.1 --- a/doc/autodoc-header.htmlpart Mon Nov 16 01:33:02 2015 +0100 1.2 +++ b/doc/autodoc-header.htmlpart Mon Nov 16 16:55:49 2015 +0100 1.3 @@ -1,5 +1,14 @@ 1.4 <html> 1.5 <head> 1.6 + <script type="text/javascript"> 1.7 + window.onload = function() { 1.8 + if (window.location.hash) { 1.9 + var encoded_hash = window.location.hash.replace(/^#/, '').replace(/_/g, '_USC_').replace(/\./g, '_DOT_').replace(/:/g, '_COL_'); 1.10 + var element = document.getElementById('autodoc_details_' + encoded_hash); 1.11 + if (element) element.style.display = ''; 1.12 + } 1.13 + } 1.14 + </script> 1.15 <style> 1.16 body { 1.17 font-family: "Liberation Sans", sans-serif;
2.1 --- a/framework/bin/autodoc.lua Mon Nov 16 01:33:02 2015 +0100 2.2 +++ b/framework/bin/autodoc.lua Mon Nov 16 16:55:49 2015 +0100 2.3 @@ -181,36 +181,41 @@ 2.4 table.sort(keys) 2.5 for idx, key in ipairs(keys) do 2.6 local entry = entries[key] 2.7 - output('<li class="autodoc_entry">\n') 2.8 + local m1, m2 = string.match(key, "<?([A-Za-z0-9_]*)>?([A-Za-z0-9_.:]+)") 2.9 + local anchor = m1 .. m2 2.10 + local ident = anchor:gsub("_", "_USC_"):gsub("%.", "_DOT_"):gsub(":", "_COL_") 2.11 + output('<a name="', anchor, '">') 2.12 + output(' <li class="autodoc_entry">\n') 2.13 output( 2.14 - ' <div class="short_synopsis"', 2.15 + ' <div class="short_synopsis"', 2.16 ' onclick="document.getElementById(\'autodoc_details_', 2.17 - idx, 2.18 + ident, 2.19 '\').style.display = document.getElementById(\'autodoc_details_', 2.20 - idx, 2.21 + ident, 2.22 '\').style.display ? \'\' : \'none\';">\n' 2.23 ) 2.24 - output(' ', encode(entry.func_call), '\n') 2.25 - output(' </div>\n') 2.26 + output(' ', encode(entry.func_call), '\n') 2.27 + output(' </div>\n') 2.28 output( 2.29 - ' <div id="autodoc_details_', 2.30 - idx, 2.31 + ' <div id="autodoc_details_', 2.32 + ident, 2.33 '" class="autodoc_details" style="display: none;">\n' 2.34 ) 2.35 - output(' <div class="autodoc_synopsis">\n') 2.36 + output(' <div class="autodoc_synopsis">\n') 2.37 output_lines(entry.synopsis) 2.38 - output(' </div>\n') 2.39 - output(' <div class="autodoc_comment">') 2.40 + output(' </div>\n') 2.41 + output(' <div class="autodoc_comment">') 2.42 for idx, line in ipairs(entry.comment) do 2.43 output(encode(line)) 2.44 if idx < #entry.comment then 2.45 output('<br/>') 2.46 end 2.47 end 2.48 - output(' </div>\n') 2.49 - output(' <div class="autodoc_source">\n') 2.50 + output('</div>\n') 2.51 + output(' <div class="autodoc_source">\n') 2.52 output_lines(entry.source) 2.53 + output(' </div>\n') 2.54 output(' </div>\n') 2.55 - output(' </div>\n') 2.56 - output('</li>\n') 2.57 + output(' </li>\n') 2.58 + output('</a>') 2.59 end