From e8ad9e33bee838b872ffa5ae77a8ad2c089bab94 Mon Sep 17 00:00:00 2001 From: Diego Nogues Date: Tue, 29 Sep 2020 23:13:50 -0300 Subject: [PATCH] Remove leading $, > and # chars from console snippets --- src/theme/book.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/theme/book.js b/src/theme/book.js index 5e386369f7..2edca0be42 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -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); } });