$(document).ready(function() { parseMd(); }); function parseMd() { var GITHUB = 'https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md'; jQuery.get(GITHUB, function(text) { console.log(text) text = removeMdToc(text); console.log(text) var converter = new showdown.Converter(); html = converter.makeHtml(text); aDiv = $('#main_container'); nodes = $.parseHTML(html); aDiv.after(nodes); insertLinks(); d3.selectAll("code").each(function() { hljs.highlightBlock(this); }); addToc(); }); } function removeMdToc(text) { var out = []; lines = text.match(/[^\r\n]+/g); insideContents = false; for (line of lines) { if (line.trim() === 'Contents') { insideContents = true; } else if (line.trim() === 'Main') { insideContents = false; } if (!insideContents) { out.push(line); } } return out.join('\n'); } function insertLinks() { $('h2').each(function() { aId = $(this).attr('id'); $(this).append('#'); }); } function addToc() { headerMain = $('#main'); nodes = $.parseHTML(TOC); headerMain.before(nodes); } var TOC = '
' + '

Contents#

\n' + '
ToC = {\n' +
'    \'1. Collections\': [List, Dict, Set, Range, Enumerate, Namedtuple, Iterator, Generator],\n' +
'    \'2. Types\':       [Type, String, Regex, Format, Numbers, Combinatorics, Datetimeᴺᴱᵂ],\n' +
'    \'3. Syntax\':      [Arguments, Splat, Inline, Closure, Decorator, Class, Enum, Exceptions],\n' +
'    \'4. System\':      [Print, Input, Command_Line_Arguments, Open, Pathᴺᴱᵂ, Command_Execution],\n' +
'    \'5. Data\':        [CSV, JSON, Pickle, SQLite, Bytes, Struct, Array, MemoryView, Deque],\n' +
'    \'6. Advanced\':    [Threading, Introspection, Metaprograming, Operator, Eval, Coroutine],\n' +
'    \'7. Libraries\':   [Progress_Bar, Plot, Table, Curses, Loggingᴺᴱᵂ, Scraping, Web, Profile,\n' +
'                       NumPy, Image, Audio]\n' +
'}\n' +
'
\n';