PK NLN).b b sphinx_copybutton/__init__.py"""A small sphinx extension to add "copy" buttons to code blocks.""" import os __version__ = "0.2.5" def scb_static_path(app): static_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '_static')) app.config.html_static_path.append(static_path) github_url = 'https://cdn.rawgit.com/choldgraf/sphinx-copybutton/master/_static/' clipboard_js_url = "https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js" def setup(app): print('Adding copy buttons to code blocks...') # Add our static path app.connect('builder-inited', scb_static_path) # Add relevant code to headers app.add_stylesheet('copybutton.css') app.add_javascript(clipboard_js_url) app.add_javascript("copybutton.js") return {"version": __version__, "parallel_read_safe": True, "parallel_write_safe": True} PK `mPMT ) sphinx_copybutton/_static/copy-button.svgPK NLN>1 ( sphinx_copybutton/_static/copybutton.css/* Copy buttons */ a.copybtn { position: absolute; top: 2px; right: 2px; width: 1em; height: 1em; padding: .3em; opacity: .3; transition: opacity 0.5s; } div.highlight { position: relative; } .highlight:hover .copybtn { opacity: 1; } /** * A minimal CSS-only tooltip copied from: * https://codepen.io/mildrenben/pen/rVBrpK * * To use, write HTML like the following: * *
Short
*/ .o-tooltip--left { position: relative; } .o-tooltip--left:after { opacity: 0; visibility: hidden; position: absolute; content: attr(data-tooltip); padding: 2px; top: 0; left: 0; background: grey; font-size: 1rem; color: white; white-space: nowrap; z-index: 2; border-radius: 2px; transform: translateX(-102%) translateY(0); transition: opacity 0.2s cubic-bezier(0.64, 0.09, 0.08, 1), transform 0.2s cubic-bezier(0.64, 0.09, 0.08, 1); } .o-tooltip--left:hover:after { display: block; opacity: 1; visibility: visible; transform: translateX(-100%) translateY(0); transition: opacity 0.2s cubic-bezier(0.64, 0.09, 0.08, 1), transform 0.2s cubic-bezier(0.64, 0.09, 0.08, 1); } PK KMLNjD ' sphinx_copybutton/_static/copybutton.js// Localization support const messages = { 'en': { 'copy': 'Copy', 'copy_to_clipboard': 'Copy to clipboard', 'copy_success': 'Copied!', 'copy_failure': 'Failed to copy', }, 'es' : { 'copy': 'Copiar', 'copy_to_clipboard': 'Copiar al portapapeles', 'copy_success': '¡Copiado!', 'copy_failure': 'Error al copiar', }, 'de' : { 'copy': 'Kopieren', 'copy_to_clipboard': 'In die Zwischenablage kopieren', 'copy_success': 'Kopiert!', 'copy_failure': 'Fehler beim Kopieren', } } let locale = 'en' if( document.documentElement.lang !== undefined && messages[document.documentElement.lang] !== undefined ) { locale = document.documentElement.lang } /** * Set up copy/paste for code blocks */ const runWhenDOMLoaded = cb => { if (document.readyState != 'loading') { cb() } else if (document.addEventListener) { document.addEventListener('DOMContentLoaded', cb) } else { document.attachEvent('onreadystatechange', function() { if (document.readyState == 'complete') cb() }) } } const codeCellId = index => `codecell${index}` // Clears selected text since ClipboardJS will select the text when copying const clearSelection = () => { if (window.getSelection) { window.getSelection().removeAllRanges() } else if (document.selection) { document.selection.empty() } } // Changes tooltip text for two seconds, then changes it back const temporarilyChangeTooltip = (el, newText) => { const oldText = el.getAttribute('data-tooltip') el.setAttribute('data-tooltip', newText) setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000) } const addCopyButtonToCodeCells = () => { // If ClipboardJS hasn't loaded, wait a bit and try again. This // happens because we load ClipboardJS asynchronously. if (window.ClipboardJS === undefined) { setTimeout(addCopyButtonToCodeCells, 250) return } const codeCells = document.querySelectorAll('div.highlight pre') codeCells.forEach((codeCell, index) => { const id = codeCellId(index) codeCell.setAttribute('id', id) const pre_bg = getComputedStyle(codeCell).backgroundColor; const clipboardButton = id => `