Is there an easier way to copy pasted code on this forum?

I am looking for an easier way to copy user pasted code at this forum.
Currently we have to mouse select everything and hit ctrl+C.
If I click inside that code, and hit ctrl+A, it selects the entire page (chromium).

I wonder if it could have a download button to save it to a file, when pasting the code we could even specify a default filename btw. Also such filename could be guessed by the site engine based on the code class name if it provides one.

Adding to that we could download all pasted code in a zip file, for the entire forum thread.

Look here for examples of how I imagined it could be.

Jump to this post. By using Gist from GitHub, we can “kind of” do that.

PS.: this forum engine is marvelous, the way elements are positioned all around, and all its features, a very pleasant experience!

Not sure I understand everything you want, but that’s the way you usually go about pasting code on the forum:

Note: as I recall that thread buries the only good way to post code to the forum… to use a line of three back ticks: ` (not single quotes but back ticks.) Followed by the code. Followed by another line of three back ticks.

The </> button is kind of broken. It does weird things to indenting and has some other problems that I can’t recall. I wish we could change the </> to do the back ticks.

Part of the issue is that the </> button is for generic pre-formatted text. ASCII art, etc should be just fine.

The following was done with the </> button, though. In simple cases, it works.
You can’t expect it to act like a word processor. I suspect that many hit the button, paste their text, and then are puzzled as to why it didn’t work like the italic control in libre office, etc.

paste, then toggle!

<div id="menu">
	<label for="menutoggler" id="menuclose">X</label>
	<ul>
		<li>home</li>
		<li>download</li>
		<li>documentation</li>
		<li>gallery</li>
	</ul>
</div>

No it’s mentioned. i even explain how to type a backtick on a windows machine and on a mac

Yeah, but every time we post a link to that thread the paragraph mentions is only talking about the bad ways. Perhaps it needs to be moved up.

oh ok
will do this

EDIT : ok I did it, but the preview seems stuck in the old version… maybe it will work later… idk

@nehon I actually meant to download the code that some other user has pasted at the forum thread, as a .java text file (.txt if unidentifiable, could be .patch too).

I thought, instead of selecting and copying code from the forum thread manually, if we could download the code other user pasted by hitting a download button?

And, if the forum thread has several pasted codes by several users, we could hit yet another download button to download the entire thread user pasted codes in a single .zip file, In this case the organization could be like this:

  • the forum user name would be the TopFolderUName on the .zip file
  • the ForumThreadPostNumericId would be the sub folder name, like in:
    TopFolderUName/ForumThreadPostNumericId
  • the pasted code FancyClassName would be the final FancyClassName.java, like in:
    TopFolderUName/ForumThreadPostNumericId/FancyClassName.java. If it is not a whole class, it could receive an indexed simple name like code003.java.

The point I dont know is about use cases/scenarios, if there are so many threads with usable pasted code that could make this functionality really useful, or it would just be something needlessly complicated, even if interesting :smile:

PS.: btw, I just saw I can “download my posts” at my profile. That is not the kind of download I mean here, because that is not a code download easyfier, but a html formatted whole posts backup kind of, in csv format.

The button works fine btw, the trick is to do it the other way round.

paste your code, select it, press the button
(and for some reason it then works, while when manually doing the prefixstuff it will not)

Unfortunately we cannot customize the forum software to this extent.

What I can think of is to use Gist to post your code (though it’s all in the poster’s hand).
You’ll have a preview of the code and you’ll be able to download it as a file, or multiple files in a zip directly on github.

1 Like

I’ve done this before and had it strip all of the formatting out… extra lines, etc… Three ticks always works and you can even specify a language preference. It also works in lots of other places (other than this forum).

@nehon gist is very interesting, It even allowed anonymous paste. We simply put the link here and it gets embedded, very good. Will use it, thx!

EDIT: but indeed, users not knowing about it cant provide that extra help to others.

Got a repro? This sounds like something the discourse team should know about. Pre-formatted text should not be edited at all…

I don’t remember what the exact issue was but sometimes the “indent the code to make it look like code” thing just flat out breaks… even when using the button. Where as the 3 back ticks has always worked 100000% of the time.

Ergo, I don’t bother with the one that “might” work and always use the one that always works… and I wish that the button would too.

I remember there was a request on Discourse forum to make the code button use back ticks.
Idk what it became, but I guess not much…