diff --git a/integtest/spec/helper/console_alternative_examples.rb b/integtest/spec/helper/console_alternative_examples.rb index 80435957a901c..8048eabafaab6 100644 --- a/integtest/spec/helper/console_alternative_examples.rb +++ b/integtest/spec/helper/console_alternative_examples.rb @@ -47,6 +47,7 @@ module ConsoleExamples it 'contains the js listing followed by the csharp listing' do expect(body).to include(<<~HTML.strip)
const result = await client.search({ body: { query: 'foo bar' } })@@ -57,6 +58,7 @@ module ConsoleExamples it 'contains the csharp listing followed by the default listing' do expect(body).to include(<<~HTML.strip)
var searchResponse = _client.Search<Project>(s => s .Query(q => q .QueryString(m => m @@ -72,6 +74,7 @@ module ConsoleExamples it 'contains the default listing followed by the console widget' do expect(body).to include(<<~HTML.strip)+GET /_search { "query": "foo bar" diff --git a/resources/asciidoctor/lib/docbook_compat/convert_listing.rb b/resources/asciidoctor/lib/docbook_compat/convert_listing.rb index 9f10d9d909e83..3be679bc25d44 100644 --- a/resources/asciidoctor/lib/docbook_compat/convert_listing.rb +++ b/resources/asciidoctor/lib/docbook_compat/convert_listing.rb @@ -52,6 +52,7 @@ def convert_listing_body_with_language(node, lang) pre_classes = "programlisting prettyprint lang-#{lang}#{extra_classes}" [ %(), + %(), %(), ].join "\n" diff --git a/resources/asciidoctor/spec/docbook_compat_spec.rb b/resources/asciidoctor/spec/docbook_compat_spec.rb index 085bdf30dcb8c..4d8650c6f276d 100644 --- a/resources/asciidoctor/spec/docbook_compat_spec.rb +++ b/resources/asciidoctor/spec/docbook_compat_spec.rb @@ -1065,6 +1065,7 @@ # It is important that there isn't any extra space around the#{node.content || ''}), %(tags expect(converted).to include(<<~HTML)+HTML @@ -1253,6 +1254,7 @@ it 'the role is included as a class' do expect(converted).to include(<<~HTML)cpanm Search::Elasticsearch+HTML diff --git a/resources/web/docs_js/index.js b/resources/web/docs_js/index.js index 9c57bee4ef798..6dbed75d3fa3c 100644 --- a/resources/web/docs_js/index.js +++ b/resources/web/docs_js/index.js @@ -437,6 +437,19 @@ $(function() { }); }); + $('div.console_code_copy').each(function () { + const $copyButton = $(this); + const langText = $copyButton.next().text(); + + $copyButton.on('click', function () { + utils.copyText(langText, lang_strings); + $copyButton.addClass('copied'); + setTimeout(function () { + $copyButton.removeClass('copied') + }, 3000); + }); + }); + var div = $('div.toc'); // Fetch toc.html unless there is already a .toc on the page diff --git a/resources/web/style/console_widget.pcss b/resources/web/style/console_widget.pcss index 5a135849b599a..5b8a5fdf532b5 100644 --- a/resources/web/style/console_widget.pcss +++ b/resources/web/style/console_widget.pcss @@ -34,4 +34,30 @@ cursor: pointer; } } + .console_code_copy { + background-image: inline("img/copy.svg"); + display: inline-block; + width: 16px; + height: 16px; + min-width: 16px; + min-height: 16px; + vertical-align: text-bottom; + align-self: center; + &:hover { + text-decoration: none !important; + cursor: pointer; + } + filter: invert(1); + position: absolute; + top: 25px; + right: 20px; + opacity: 0.7; + } + + .console_code_copy:hover { + opacity: 1; + } + .console_code_copy.copied { + background-image: inline("img/check.svg"); + } } diff --git a/resources/web/style/img/check.svg b/resources/web/style/img/check.svg new file mode 100644 index 0000000000000..c73382e30b2c8 --- /dev/null +++ b/resources/web/style/img/check.svg @@ -0,0 +1 @@ + diff --git a/resources/web/style/img/copy.svg b/resources/web/style/img/copy.svg new file mode 100644 index 0000000000000..3588cfcf35145 --- /dev/null +++ b/resources/web/style/img/copy.svg @@ -0,0 +1 @@ +cpanm Search::Elasticsearch