You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
3.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. $(document).ready(function() {
  2. parseMd();
  3. });
  4. function parseMd() {
  5. var GITHUB =
  6. "https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md";
  7. jQuery.get(GITHUB, function(text) {
  8. var converter = new showdown.Converter();
  9. html = converter.makeHtml(text);
  10. aDiv = $("#main_container");
  11. nodes = $.parseHTML(html);
  12. aDiv.after(nodes);
  13. removeOrigToc();
  14. addToc();
  15. insertLinks();
  16. unindentBanner();
  17. d3.selectAll("code").each(function() {
  18. hljs.highlightBlock(this);
  19. });
  20. });
  21. }
  22. function removeOrigToc() {
  23. headerContents = $("#contents");
  24. contentsList = headerContents.next();
  25. headerContents.remove();
  26. contentsList.remove();
  27. }
  28. function insertLinks() {
  29. $("h2").each(function() {
  30. aId = $(this).attr("id");
  31. text = $(this).text();
  32. $(this).html('<a href="#' + aId + '" name="' + aId + '">#</a>' + text);
  33. });
  34. }
  35. function unindentBanner() {
  36. let montyImg = $("img").first();
  37. montyImg.parent().addClass("banner");
  38. let downloadPraragrapth = $("p").first();
  39. downloadPraragrapth.addClass("banner");
  40. }
  41. function addToc() {
  42. headerMain = $("#main");
  43. nodes = $.parseHTML(TOC);
  44. headerMain.before(nodes);
  45. }
  46. var TOC =
  47. "<br>" +
  48. '<h2 id="toc">Contents</h2>\n' +
  49. '<pre><code class="hljs bash"><strong>ToC</strong> = {\n' +
  50. ' <strong><span class="hljs-string">\'1. Collections\'</span></strong>: [<a href="#list">List</a>, <a href="#dictionary">Dict</a>, <a href="#set">Set</a>, <a href="#range">Range</a>, <a href="#enumerate">Enumerate</a>, <a href="#namedtuple">Namedtuple</a>, <a href="#iterator">Iterator</a>, <a href="#generator">Generator</a>],\n' +
  51. ' <strong><span class="hljs-string">\'2. Types\'</span></strong>: [<a href="#type">Type</a>, <a href="#string">String</a>, <a href="#regex">Regex</a>, <a href="#format">Format</a>, <a href="#numbers">Numbers</a>, <a href="#combinatorics">Combinatorics</a>, <a href="#datetime">Datetime</a>ᴺᴱᵂ],\n' +
  52. ' <strong><span class="hljs-string">\'3. Syntax\'</span></strong>: [<a href="#arguments">Arguments</a>, <a href="#splatoperator">Splat</a>, <a href="#inline">Inline</a>, <a href="#closure">Closure</a>, <a href="#decorator">Decorator</a>, <a href="#class">Class</a>, <a href="#enum">Enum</a>, <a href="#exceptions">Exceptions</a>],\n' +
  53. ' <strong><span class="hljs-string">\'4. System\'</span></strong>: [<a href="#print">Print</a>, <a href="#input">Input</a>, <a href="#commandlinearguments">Command_Line_Arguments</a>, <a href="#open">Open</a>, <a href="#path">Path</a>ᴺᴱᵂ, <a href="#commandexecution">Command_Execution</a>],\n' +
  54. ' <strong><span class="hljs-string">\'5. Data\'</span></strong>: [<a href="#csv">CSV</a>, <a href="#json">JSON</a>, <a href="#pickle">Pickle</a>, <a href="#sqlite">SQLite</a>, <a href="#bytes">Bytes</a>, <a href="#struct">Struct</a>, <a href="#array">Array</a>, <a href="#memoryview">MemoryView</a>, <a href="#deque">Deque</a>],\n' +
  55. ' <strong><span class="hljs-string">\'6. Advanced\'</span></strong>: [<a href="#threading">Threading</a>, <a href="#introspection">Introspection</a>, <a href="#metaprograming">Metaprograming</a>, <a href="#operator">Operator</a>, <a href="#eval">Eval</a>, <a href="#coroutine">Coroutine</a>],\n' +
  56. ' <strong><span class="hljs-string">\'7. Libraries\'</span></strong>: [<a href="#progressbar">Progress_Bar</a>, <a href="#plot">Plot</a>, <a href="#table">Table</a>, <a href="#curses">Curses</a>, <a href="#logging">Logging</a>ᴺᴱᵂ, <a href="#scraping">Scraping</a>, <a href="#web">Web</a>, <a href="#profile">Profile</a>,\n' +
  57. ' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>]\n' +
  58. "}\n" +
  59. "</code></pre>\n";