@@ -3,25 +3,42 @@ $(document).ready(function() {
3
3
} ) ;
4
4
5
5
function parseMd ( ) {
6
- var GITHUB = 'https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md' ;
6
+ var GITHUB =
7
+ "https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md" ;
7
8
jQuery . get ( GITHUB , function ( text ) {
9
+ console . log ( text ) ;
10
+ text = removeMdToc ( text ) ;
11
+ console . log ( text ) ;
8
12
var converter = new showdown . Converter ( ) ;
9
13
html = converter . makeHtml ( text ) ;
10
- aDiv = $ ( ' #main_container' ) ;
14
+ aDiv = $ ( " #main_container" ) ;
11
15
nodes = $ . parseHTML ( html ) ;
12
16
aDiv . after ( nodes ) ;
13
17
removeOrigToc ( ) ;
14
18
insertLinks ( ) ;
15
- d3 . selectAll ( "code" ) . each ( function ( ) { hljs . highlightBlock ( this ) ; } ) ;
19
+ addImgParentClass ( ) ;
20
+ d3 . selectAll ( "code" ) . each ( function ( ) {
21
+ hljs . highlightBlock ( this ) ;
22
+ } ) ;
16
23
addToc ( ) ;
17
24
} ) ;
18
25
}
19
26
20
- function removeOrigToc ( ) {
21
- headerContents = $ ( '#contents' )
22
- contentsList = headerContents . next ( )
23
- headerContents . remove ( )
24
- contentsList . remove ( )
27
+ function removeMdToc ( text ) {
28
+ var out = [ ] ;
29
+ lines = text . match ( / [ ^ \r \n ] + / g) ;
30
+ insideContents = false ;
31
+ for ( line of lines ) {
32
+ if ( line . trim ( ) === "Contents" ) {
33
+ insideContents = true ;
34
+ } else if ( line . trim ( ) === "Main" ) {
35
+ insideContents = false ;
36
+ }
37
+ if ( ! insideContents ) {
38
+ out . push ( line ) ;
39
+ }
40
+ }
41
+ return out . join ( "\n" ) ;
25
42
}
26
43
27
44
function insertLinks ( ) {
@@ -32,29 +49,28 @@ function insertLinks() {
32
49
} ) ;
33
50
}
34
51
function addImgParentClass ( ) {
35
- $ ( "img" ) . each ( function ( ) {
36
- $ ( this )
37
- . parent ( )
38
- . addClass ( "img_parent" ) ;
39
- } ) ;
52
+ let monty_img = $ ( "img" ) . first ( ) ;
53
+ monty_img . parent ( ) . addClass ( "img_parent" ) ;
54
+ monty_img . before ( "<br>" ) ;
40
55
}
41
56
42
57
function addToc ( ) {
43
- headerMain = $ ( ' #main' ) ;
58
+ headerMain = $ ( " #main" ) ;
44
59
nodes = $ . parseHTML ( TOC ) ;
45
60
headerMain . before ( nodes ) ;
46
61
}
47
62
48
- var TOC = '<br>' +
49
- '<h2 id="toc">Contents<a href="#toc" name="toc">#</a></h2>\n' +
50
- '<pre><code class="hljs bash"><strong>ToC</strong> = {\n' +
51
- ' <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' +
52
- ' <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' +
53
- ' <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' +
54
- ' <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' +
55
- ' <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' +
56
- ' <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' +
57
- ' <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' +
58
- ' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>]\n' +
59
- '}\n' +
60
- '</code></pre>\n' ;
63
+ var TOC =
64
+ "<br>" +
65
+ '<h2 id="toc">Contents<a href="#toc" name="toc">#</a></h2>\n' +
66
+ '<pre><code class="hljs bash"><strong>ToC</strong> = {\n' +
67
+ ' <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' +
68
+ ' <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' +
69
+ ' <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' +
70
+ ' <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' +
71
+ ' <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' +
72
+ ' <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' +
73
+ ' <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' +
74
+ ' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>]\n' +
75
+ "}\n" +
76
+ "</code></pre>\n" ;
0 commit comments