Skip to content

Commit 5b90090

Browse files
author
ogogorev
committed
remove empty space in short version for code blocks
1 parent 5a739cd commit 5b90090

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

_theme/tarantool/static/js/copy-button.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ $(document).ready(function() {
2525
div.each(function(index) {
2626
var jthis = $(this);
2727
if (jthis.find('.gp').length > 0) {
28+
// add copy-pasteable version
29+
jthis.find("pre").addClass('full');
30+
var shortVersion = jthis.find("pre").clone();
31+
shortVersion.find('.p-Indicator').nextUntil('.nn').remove();
32+
shortVersion.find('.go, .gp, .gt, .nn, .c1, .no, .p-Indicator').remove();
33+
shortVersion.find('.gt').nextUntil('.gp, .go').remove();
34+
shortVersion.removeClass("full");
35+
shortVersion.addClass("short");
36+
shortVersion.hide();
37+
38+
shortVersion.find('span').each(function(i, v) {
39+
if ($(v).text() === '') $(v).remove();
40+
});
41+
42+
var html = shortVersion.html();
43+
html = html.split('\n').map(function(v) {
44+
if (/^\s*<span/.test(v)) return v;
45+
else return v.trim();
46+
}).filter(function(v) {
47+
return v != '';
48+
}).join('\n');
49+
shortVersion.html(html);
50+
jthis.prepend(shortVersion);
51+
52+
//add button
2853
var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
2954
button.css(button_styles)
3055
button.attr('title', hide_text);
@@ -44,17 +69,15 @@ $(document).ready(function() {
4469
var button = $(this);
4570
if (button.data('hidden') === 'false') {
4671
// hide the code output
47-
button.next('pre').find('.p-Indicator').nextUntil('.nn').css('visibility', 'hidden');
48-
button.parent().find('.go, .gp, .gt, .nn, .c1, .no, .p-Indicator').hide();
49-
button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
72+
button.parent().find('.full').hide();
73+
button.parent().find('.short').show();
5074
button.css('text-decoration', 'line-through');
5175
button.attr('title', show_text);
5276
button.data('hidden', 'true');
5377
} else {
5478
// show the code output
55-
button.next('pre').find('.p-Indicator').nextUntil('.nn').css('visibility', 'visible');
56-
button.parent().find('.go, .gp, .gt, .nn, .c1, .no, .p-Indicator').show();
57-
button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
79+
button.parent().find('.full').show();
80+
button.parent().find('.short').hide();
5881
button.css('text-decoration', 'none');
5982
button.attr('title', hide_text);
6083
button.data('hidden', 'false');

0 commit comments

Comments
 (0)