Browse Source

Updated script.js

pull/31/head
Jure Šorn 5 years ago
parent
commit
b053d86754
2 changed files with 14 additions and 17 deletions
  1. 7
      index.html
  2. 24
      parse.js

7
index.html

@ -318,7 +318,7 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>
<li><strong>Every class is a subclass and a superclass of itself.</strong></li>
</ul>
<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
(&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;)
(&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;)
</span></code></pre>
<h4 id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have builtin names, so they must be imported:</h4>
<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 @@ creature = Creature()
<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>
</code></pre>
<p><strong>MRO determines the order in which parent classes are traversed when searching for a method:</strong></p>
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>C.mro()
[&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>
</pre>
[&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></pre>
<h3 id="copy">Copy</h3>
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> copy <span class="hljs-keyword">import</span> copy, deepcopy
&lt;object&gt; = copy(&lt;object&gt;)

24
parse.js

@ -30,8 +30,6 @@ const TOC =
'}\n' +
'</code></pre>\n';
const MRO =
'<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'
function main() {
const html = getMd();
@ -94,23 +92,23 @@ function unindentBanner() {
}
function highlightCode() {
setApache('<D>')
setApache('<T>')
setApache('<DT>')
setApache('<TD>')
setApache('<a>')
setApache('<n>')
setApaches(['<D>', '<T>', '<DT>', '<TD>', '<a>', '<n>']);
$('code').not('.python').not('.text').not('.bash').not('.apache').addClass('python');
$('code').each(function(index) {
hljs.highlightBlock(this);
});
$('#copy').prev().remove()
const nodes = $.parseHTML(MRO);
$('#copy').before(nodes);
fixClasses()
}
function setApache(codeContents) {
$(`code:contains(${codeContents})`).addClass('apache');
function setApaches(elements) {
for (el of elements) {
$(`code:contains(${el})`).addClass('apache');
}
}
function fixClasses() {
// Changes class="hljs-keyword" to class="hljs-title" of 'class' keyword.
$('.hljs-class').filter(':contains(class \')').find(':first-child').removeClass('hljs-keyword').addClass('hljs-title')
}
function readFile(filename) {

Loading…
Cancel
Save