-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Strip $ symbol from code block text #1110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,19 @@ window.onunload = function () { }; | |
// Global variable, shared between modules | ||
function playpen_text(playpen) { | ||
let code_block = playpen.querySelector("code"); | ||
let regex = /^\$(?: )/; | ||
|
||
if (window.ace && code_block.classList.contains("editable")) { | ||
let editor = window.ace.edit(code_block); | ||
return editor.getValue(); | ||
} else { | ||
return code_block.textContent; | ||
// It is common for code blocks to contain $ in the text. If they do, clipboard will copy that symbol and the ensuing paste into terminal will fail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is great because it explains the motivation. I would specify that the dollar sign convention is common for bash / shell specifically, not all code blocks. AndI would expand this comment to mention briefly how this is solved (stripping dollar signs) |
||
if (regex.test(code_block.textContent)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this |
||
let clean_string = code_block.textContent.replace(regex, "") | ||
return clean_string; | ||
} else { | ||
return code_block.textContent; | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest a more explicit variable name for this regex.