Skip to content

Commit b053d86

Browse files
committed
Updated script.js
1 parent 69e31bb commit b053d86

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ <h2 id="type"><a href="#type" name="type">#</a>Type</h2>
318318
<li><strong>Every class is a subclass and a superclass of itself.</strong></li>
319319
</ul>
320320
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>type(<span class="hljs-string">'a'</span>), <span class="hljs-string">'a'</span>.__class__, str
321-
(&lt;<span class="hljs-class"><span class="hljs-keyword">class</span> '<span class="hljs-title">str</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;)
321+
(&lt;<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;)
322322
</span></code></pre>
323323
<h4 id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have builtin names, so they must be imported:</h4>
324324
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> types <span class="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType
@@ -770,10 +770,9 @@ <h3 id="multipleinheritance">Multiple Inheritance</h3>
770770
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">C</span><span class="hljs-params">(A, B)</span>:</span> <span class="hljs-keyword">pass</span>
771771
</code></pre>
772772
<p><strong>MRO determines the order in which parent classes are traversed when searching for a method:</strong></p>
773-
774773
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>C.mro()
775-
[&lt;<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">C</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">A</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">B</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">object</span>'&gt;]</span></code>
776-
</pre>
774+
[&lt;<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">C</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">A</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">B</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">object</span>'&gt;]
775+
</span></code></pre>
777776
<h3 id="copy">Copy</h3>
778777
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> copy <span class="hljs-keyword">import</span> copy, deepcopy
779778
&lt;object&gt; = copy(&lt;object&gt;)

parse.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ const TOC =
3030
'}\n' +
3131
'</code></pre>\n';
3232

33-
const MRO =
34-
'<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>C.mro()\n[&lt;<span class="hljs-class"><span class="hljs-title">class</span> \'<span class="hljs-title">C</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">A</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">B</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">object</span>\'&gt;]</span></code>\n</pre>\n'
3533

3634
function main() {
3735
const html = getMd();
@@ -94,23 +92,23 @@ function unindentBanner() {
9492
}
9593

9694
function highlightCode() {
97-
setApache('<D>')
98-
setApache('<T>')
99-
setApache('<DT>')
100-
setApache('<TD>')
101-
setApache('<a>')
102-
setApache('<n>')
95+
setApaches(['<D>', '<T>', '<DT>', '<TD>', '<a>', '<n>']);
10396
$('code').not('.python').not('.text').not('.bash').not('.apache').addClass('python');
10497
$('code').each(function(index) {
10598
hljs.highlightBlock(this);
10699
});
107-
$('#copy').prev().remove()
108-
const nodes = $.parseHTML(MRO);
109-
$('#copy').before(nodes);
100+
fixClasses()
110101
}
111102

112-
function setApache(codeContents) {
113-
$(`code:contains(${codeContents})`).addClass('apache');
103+
function setApaches(elements) {
104+
for (el of elements) {
105+
$(`code:contains(${el})`).addClass('apache');
106+
}
107+
}
108+
109+
function fixClasses() {
110+
// Changes class="hljs-keyword" to class="hljs-title" of 'class' keyword.
111+
$('.hljs-class').filter(':contains(class \')').find(':first-child').removeClass('hljs-keyword').addClass('hljs-title')
114112
}
115113

116114
function readFile(filename) {

0 commit comments

Comments
 (0)