diff --git a/web/script.js b/web/script.js index aa2159d..8f78d47 100644 --- a/web/script.js +++ b/web/script.js @@ -1,51 +1,50 @@ $(document).ready(function() { - parseMd() + parseMd(); }); function parseMd() { - var GITHUB = 'https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md' + var GITHUB = 'https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md'; jQuery.get(GITHUB, function(text) { - text = removeMdToc(text) - var converter = new showdown.Converter() - html = converter.makeHtml(text) - aDiv = $('#main_container') - nodes = $.parseHTML(html) + text = removeMdToc(text); + var converter = new showdown.Converter(); + html = converter.makeHtml(text); + aDiv = $('#main_container'); + nodes = $.parseHTML(html); aDiv.after(nodes); - insertLinks() + insertLinks(); d3.selectAll("code").each(function() { hljs.highlightBlock(this); }); - addToc() + addToc(); }); } function removeMdToc(text) { - var out = [] + var out = []; lines = text.match(/[^\r\n]+/g); - console.log(lines) - insideContents = false + insideContents = false; for (line of lines) { if (line.trim() === 'Contents') { - insideContents = true + insideContents = true; } else if (line.trim() === 'Main') { - insideContents = false + insideContents = false; } if (!insideContents) { - out.push(line) + out.push(line); } } - return text + return out.join(); } function insertLinks() { $('h2').each(function() { - aId = $(this).attr('id') - $(this).append('#') + aId = $(this).attr('id'); + $(this).append('#'); }) } function addToc() { - headerMain = $('#main') - nodes = $.parseHTML(TOC) - headerMain.before(nodes) + headerMain = $('#main'); + nodes = $.parseHTML(TOC); + headerMain.before(nodes); } var TOC = '
' + @@ -60,4 +59,4 @@ var TOC = '
' + ' \'7. Libraries\': [Progress_Bar, Plot, Table, Curses, Loggingᴺᴱᵂ, Scraping, Web, Profile,\n' + ' NumPy, Image, Audio]\n' + '}\n' + -'\n' +'\n';