Skip to content
Closed
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
13 changes: 13 additions & 0 deletions src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,23 @@ function playground_text(playground) {
elem.className = 'fa fa-copy tooltipped';
}

// this will remove '$', '>' and '#' leading characters
// from clipboard of console snippets
function removeLeadingChars(str) {
var leading_chars_expr = /^(\$|\>|\#)\s/gm;
return str.replace(leading_chars_expr, '');
}

var clipboardSnippets = new ClipboardJS('.clip-button', {
text: function (trigger) {
hideTooltip(trigger);
let playground = trigger.closest("pre");

// evaluates if the code block is of type console
let isConsole = playground.querySelector("code").classList.contains("language-console");
if (isConsole === true)
return removeLeadingChars(playground_text(playground));

return playground_text(playground);
}
});
Expand Down