Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37ebca5

Browse files
committed
pyshell: add syntax highlighting
1 parent 921d998 commit 37ebca5

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## python-markdown2 2.4.1 (not yet released)
44

55
- [pull #389] Tables extra: allow whitespace at the end of the underline row
6+
- [pull #392] Pyshell extra: enable syntax highlighting if `fenced-code-blocks` is loaded.
67

78

89
## python-markdown2 2.4.0

lib/markdown2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,9 @@ def _run_block_gamut(self, text):
10291029
return text
10301030

10311031
def _pyshell_block_sub(self, match):
1032+
if "fenced-code-blocks" in self.extras:
1033+
dedented = _dedent(match.group(0))
1034+
return self._do_fenced_code_blocks("```pycon\n" + dedented + "```\n")
10321035
lines = match.group(0).splitlines(0)
10331036
_dedentlines(lines)
10341037
indent = ' ' * self.tab_width
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<h1>From Recipe 302035</h1>
2+
3+
<p>Some examples:</p>
4+
5+
<div class="codehilite"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="n">nprint</span><span class="p">(</span><span class="mi">9876543210</span><span class="p">)</span>
6+
<span class="go">&#39;9 876 543 210&#39;</span>
7+
<span class="gp">&gt;&gt;&gt; </span><span class="n">nprint</span><span class="p">(</span><span class="mi">987654321</span><span class="p">,</span> <span class="n">period</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">delimiter</span><span class="o">=</span><span class="s2">&quot;,&quot;</span><span class="p">)</span>
8+
<span class="go">&#39;9,8,7,6,5,4,3,2,1,0&#39;</span>
9+
</code></pre></div>
10+
11+
<p>Indented a bit:</p>
12+
13+
<div class="codehilite"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>
14+
<span class="go">2</span>
15+
</code></pre></div>
16+
17+
<p>Cuddled to previous para (and at end of document):</p>
18+
19+
<div class="codehilite"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span>
20+
<span class="go">4</span>
21+
</code></pre></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"extras": ["pyshell", "fenced-code-blocks"]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extra fenced-code-blocks pygments pyshell
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# From Recipe 302035
2+
3+
Some examples:
4+
5+
>>> nprint(9876543210)
6+
'9 876 543 210'
7+
>>> nprint(987654321, period=1, delimiter=",")
8+
'9,8,7,6,5,4,3,2,1,0'
9+
10+
Indented a bit:
11+
12+
>>> 1 + 1
13+
2
14+
15+
Cuddled to previous para (and at end of document):
16+
>>> 2 + 2
17+
4

0 commit comments

Comments
 (0)