Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sphinx_copybutton/_static/copybutton_funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ export function formatCopyText(textContent, copybuttonPromptText, isRegexp = fal
const lineGotPrompt = [];
for (const line of textContent.split('\n')) {
match = line.match(regexp)
if (!match) {
// Blank REPL lines are often ">>>" without the trailing space in ">>> ".
const padded = (line + ' ').match(regexp)
if (padded && padded[2] === '') {
match = padded
}
}
if (match || gotLineCont || gotHereDoc) {
promptFound = regexp.test(line)
promptFound = !!match
lineGotPrompt.push(promptFound)
if (removePrompts && promptFound) {
outputLines.push(match[2])
Expand Down
25 changes: 25 additions & 0 deletions sphinx_copybutton/_static/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ output
removePrompts: true,
expected: '\nfirst\nsecond'
},
{
description: 'with non-regexp python prompt and blank REPL line',
text: `
>>> first
>>>
>>> second`,
prompt: '>>> ',
isRegexp: false,
onlyCopyPromptLines: true,
removePrompts: true,
expected: '\nfirst\n\nsecond'
},
{
description: 'with regexp python prompt and blank REPL line',
text: `
>>> first
>>>
>>> second`,
prompt: '>>> ',
isRegexp: true,
onlyCopyPromptLines: true,
removePrompts: true,
copyEmptyLines: true,
expected: '\nfirst\n\nsecond'
},
{
description: 'with non-regexp console prompt',
text: `
Expand Down