This question already has an answer here:

When reviewing, I often find myself copying the source to open in an IDE locally. Maybe we could add a button to download the source snippets to help facilitate this?

share

marked as duplicate by Vogel612, Community 2 days ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
To copy from a website to your editor? Or just to copy the code block? – Joe Wallis 2 days ago
    
@JoeWallis To download the snippet to a file with the correct extension. – rookie 2 days ago
1  
There have been regulars doing something like this already. If you give me a minute I'll make it an answer. – Mast 2 days ago
    
Possibly related: codereview.stackexchange.com/a/41210/31562 . I think the best bet would be to make a userscript for it, possibly one that provides a link or makes a request to some webservice that fetches the post and provides a downloadable file. I don't really expect Stack Exchange to provide a feature for this. – Simon Forsberg 2 days ago
    
The question got closed before I could finish my answer, see the answer on the linked question instead. As far as the request itself goes, I don't give it much chance. Sure, it would be great. But it would have to support quite some languages and we review the weirdest things here. It would be quite a heavy feature relevant for only one site. – Mast yesterday

I have the following code in a toolbar button's URL:

javascript: $('pre.prettyprint').not('button + *').each( function()  {     /* Thank you http://stackoverflow.com/a/2838358/7602 */    function selectCode(el, win)     {      win = win || window;      var doc = win.document, sel, range;      if (win.getSelection && doc.createRange)       {        sel = win.getSelection();        range = doc.createRange();        range.selectNodeContents(el);        sel.removeAllRanges();        sel.addRange(range);      }       else if (doc.body.createTextRange)       {        range = doc.body.createTextRange();        range.moveToElementText(el);        range.select();      }    }    var buttonText  = 'Select Code',        length      = buttonText.length,        codeBlock   = this,        $link       = $('<button type=\'button\'>' + buttonText + '</button>').click(function()        {          console.log( $(codeBlock).text().substring( length ) );          selectCode(codeBlock);        });    $(codeBlock).before( $link );  });void(0);

I cannot recall where I found it.

It then becomes a button on your Chrome toolbar that, when you press, adds "Select Code" to each code block in the question/answer......

enter image description here

share

Not the answer you're looking for? Browse other questions tagged .