clipboard: remove trailing line break from copied text #175

This commit is contained in:
Sören Weber 2022-02-22 20:36:59 +01:00
parent e4f0ed138c
commit d850ea528d
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589

View file

@ -341,18 +341,23 @@ jQuery(function() {
var clip = new ClipboardJS('.copy-to-clipboard-button', {
text: function(trigger) {
var text = $(trigger).prev('code').text();
// remove a trailing line break, this may most likely
// come from the browser / Hugo transformation
text = text.replace(/\n$/, '');
// removes leading $ signs from text in an assumption
// that this has to be the unix prompt marker - weird
return text.replace(/^\$\s/gm, '');
}
});
clip.on('success', function(e) {
e.clearSelection();
var inPre = $(e.trigger).parent().parent().prop('tagName') == 'PRE';
var inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
});
clip.on('error', function(e) {
var inPre = $(e.trigger).parent().parent().prop('tagName') == 'PRE';
var inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
$(document).one('copy', function(){
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));