Skip to content

Commit

Permalink
enh(python) Added python-repl for Python REPL sessions (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Feb 23, 2020
1 parent 48a3ba9 commit 83996aa
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

New languages:

- none.
- enh(python) Added `python-repl` for Python REPL sessions

New themes:

Expand Down
29 changes: 29 additions & 0 deletions src/languages/python-repl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Language: Python REPL
Requires: python.js
Author: Josh Goebel <hello@joshgoebel.com>
Category: common
*/

export default function(hljs) {
return {
aliases: ['pycon'],
contains: [
{
className: 'meta',
starts: {
// a space separates the REPL prefix from the actual code
// this is purely for cleaner HTML output
end: / |$/,
starts: {
end: '$', subLanguage: 'python'
}
},
variants: [
{ begin: /^>>>(?=[ ]|$)/ },
{ begin: /^\.\.\.(?=[ ]|$)/ }
]
},
]
}
}
15 changes: 15 additions & 0 deletions test/detect/python-repl/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
>>> v = "foo = 42"
>>> v
"foo = 42"
>>> print(v)
foo = 42
>>> print(repr(v).rstrip('"'))
"foo = 42
>>> print(repr(v).lstrip('"'))
foo = 42"

>>> """
... abc
... """
>>> def test():
... pass
17 changes: 17 additions & 0 deletions test/markup/python-repl/sample.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python">v = <span class="hljs-string">"foo = 42"</span></span>
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python">v</span>
"foo = 42"
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python">print(v)</span>
foo = 42
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python">print(repr(v).rstrip(<span class="hljs-string">'"'</span>))</span>
"foo = 42
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python">print(repr(v).lstrip(<span class="hljs-string">'"'</span>))</span>
foo = 42"

<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python"><span class="hljs-string">"""</span></span>
<span class="hljs-meta">...</span> <span class="python"><span class="hljs-string">abc</span></span>
<span class="hljs-meta">...</span> <span class="python"><span class="hljs-string">"""</span></span>
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test</span><span class="hljs-params">()</span>:</span></span>
<span class="hljs-meta">...</span> <span class="python"> <span class="hljs-keyword">pass</span></span>
<span class="hljs-meta">&gt;&gt;&gt;</span>
<span class="hljs-meta">&gt;&gt;&gt;</span>
17 changes: 17 additions & 0 deletions test/markup/python-repl/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
>>> v = "foo = 42"
>>> v
"foo = 42"
>>> print(v)
foo = 42
>>> print(repr(v).rstrip('"'))
"foo = 42
>>> print(repr(v).lstrip('"'))
foo = 42"

>>> """
... abc
... """
>>> def test():
... pass
>>>
>>>

0 comments on commit 83996aa

Please sign in to comment.