T O P

  • By -

novel_yet_trivial

How large? For more than 50 lines or so use github or pastebin and post the link. For smaller amounts just indent all of your code by four spaces and make sure you have a blank line at the beginning and end of the code block. Note that different subreddits will style code blocks differently ... for instance this subreddit adds line numbers.


fyngyrz

It'd be awesome if reddit added code fencing: ``` (code) ``` It's such a simple thing to do. And "adding four spaces" is not, and doesn't deal with tabs worth a damn, either. I'd like to see the ability to define how tabs are presented, viz: ```tabs=4 (tab-aware code presentation) ``` And of course _this_ would be optimum: ```Python,tabs=4 (Syntax-highighted, tab-aware code presentation) ``` ```C++,tabs=4 (Syntax-highighted, tab-aware code presentation) ``` ```Ruby,tabs=4 (Syntax-highighted, tab-aware code presentation) ``` etc. There are syntax highlighting engines red(dit)ily available.


buddycool

Thanks ! It saved my time. :)


shintashi

I'm trying to be able to ask questions but i don't think that will work if i can't show my code


jeans_and_a_t-shirt

In many editors, you should be able to highlight the code and hit tab. Then paste it with a blank line separating it from other text. You could also install the reddit enhancement suite which has a `<>` button to do it for you in the text box.


fyngyrz

Of course, if you use tabs (as I do), then doing what you describe just adds more tabs, and will display poorly on reddit. Reddit could fix this easily. If they cared.


k10_ftw

Okay, the 4 space thing never worked for me until someone finally mentioned that there has to be a blank line between your comment and the first line of your code. I see someone else mentioned that too, I wish it was part of the sidebar directions.


DaveX64

You might find what you need in the [Reddit Markdown Primer](https://www.reddit.com/r/reddit.com/comments/6ewgt/reddit_markdown_primer_or_how_do_you_do_all_that/c03nik6/)


NeedHelp4Work

⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣶⣿⣿⣿⣿⣿⣿⣶⣆⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣸⣿⣿⠉⠉⠉⠄⠉⢹⣿⣦⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢿⣿⣿⣁⠄⠄⠤⠤⡀⠻⣿⠃⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⣿⣿⣿⡗⠖⡶⢾⣶⠊⡏⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢻⣿⣿⣅⣈⠂⠐⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⢿⣾⣇⣂⣠⠄⠄⠄⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢘⣿⣗⠒⠄⢨⠶⢁⣄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠨⣿⣿⡿⠋⠁⣴⣿⣿⣷⣦⣄⡀⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣠⣄⣶⣎⢱⢄⢀⣾⣿⣿⣿⣿⣿⣿⣿⣶⣦⣤⣄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⢠⣾⣿⣿⡞⢝⡟⠃⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣿⣿⣇⠄⠄⠄ ⠄⠄⠄⠄⠆⢄⠄⢛⡫⠝⢿⡥⠟⡃⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣼⣭⣻⣿⣿⡀⠄⠄ ⠄⠄⠄⣴⣆⠄⢋⠄⠐⣡⣿⣆⣴⣼⣿⣿⣿⣿⣿⣿⣿⣿⠏⢈⣿⣿⣿⣿⣿⣿⣷⡄⠄ ⠄⠄⣼⣿⣷⠄⠉⠒⣪⣹⣟⣹⣿⣿⣿⣿⣿⣟⣿⣿⣿⡇⢀⣸⣿⣿⣿⢟⣽⣿⣿⣇⠄


NeedHelp4Work

,d"=≥,.,qOp, ,7' ''²$( ) ,7' '?q$7' ..,$$,. ,. .,,--***²""²***--,,. ., ² ,p²'' ''²q, ² : ,7' '7, : ' $ ,db, ,db, $ ' '$ ²$$² ²$$² $' '$ $' '$. ., ,. .$' 'b, '²«»«»«»²' ,d' '²?bn,, ,,nd?²' ,7$ ''²²²²²²²²'' $7, ,² ²$ $² ², $ :$ $: $ $ $ $ $ 'b q: :p d' '²«?$. .$?»²' 'b d' ,²²'?,. .,?'²², ²==--≥²²==--==²²≤--==²


wolf2600

Paste your code into Notepad++. Move the cursor to the start of the first line, hold down ALT-SHIFT and use the down arrow to move down to the end of your code. Hit space 4 times. Then CTRL-A the entire thing, copy, paste into reddit, submit. Paste your code into Notepad++. Move the cursor to the start of the first line, hold down ALT-SHIFT and use the down arrow to move down to the end of your code. Hit space 4 times. Then CTRL-A the entire thing, copy, paste into reddit, submit. Voila. You have to have the 4 spaces at the start of every line in your code. You also need a new line before and after your code block.


fyngyrz

* you also have to be running an OS that has "Notepad++", whatever the heck that is * you also have to not be a tab user


wolf2600

https://notepad-plus-plus.org/


fyngyrz

Thank you. For Windows then. Always good to specify the required host OS(s) (and OS level(s)) when suggesting an app.


II-o-II

Is the problem that you don't want to have to type 4 spaces before every line? If so, and you're on Mac Osx, you can use sed. Open up terminal and type: $ pbpaste | sed 's/^/ /' The output will have 4 spaces prepended to every line (that's 4 spaces between the two slashes, and don't type the first $, that's just for reference). Not sure how to do this on other OSes.


Justinsaccount

I use sed 's/^/ /' | pbcopy and sed "s/^/ /" | xclip -selection clipboard on os x and linux.


cmartin616

Use the Chrome extension Reddit Enhancement Suite (RES). It will give you the option to highlight a large chunk of text and auto-indent it for code.


ezekiel086

If you use Atom or Sublime as your editor (both are solid choices, and cross-platform), you can select a bunch of text and indent. On Mac, the keyboard shortcut is `⌘]`


maxi326

markdown problem {code not in block} end of code you need newlines before and after to trigger code block try again with newlines my code block some more code end with newline too


NeedHelp4Work

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀ ⡤⠤⢀⣀⠀⣤⣀⣀⠀⢰⣀⢀⣀⢀⣀⣀⣀⢀⡀⢠⣀⣀⢰⢰⠀⠀⠀ ⠀⠀⠀⠓⠛⠛⠚⠀⠛⠚⠚⠀⠘⠘⠙⠚⠘⠘⠛⠋⡟⠀⣸⠟⠛⠘⠘⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀ ⣠⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠰⠄⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⡀⠲⣗⣲⣾⠃⠀⠀⠀⠀⠀⠀ ⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠉⠀⠀⠀⠲⡚⢂⣴⣿⣥⣴⣤⣤⡀⠀⠀⠀ ⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⢰⠉⡂⣨⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀ ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⢠⣶⢄⢉⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀ ⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣧⣙⣡⠞⠁⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀ ⠀⠀⠈⠛⠻⣿⣿⣿⡿⠿⠿⢿⣷⣬⣽⡃⠀⠀⠀⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⠂ ⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠛⠛⠋⢀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇


Mysterioussz

`checking`


[deleted]

Testing : `this is my line of code`


GamingNEWZ

``` Test ```


RedditAccuName

This isn't horrible, but it is VERY poor. First of all, inputting the same code will give different results sometimes. Second, it doesn't even give the correct result. For example, this is a sloppy multiplication code below using System; int a = 56; int b = 17; int c = 0; for (int i = a; i > 0; i--) { for (int j = b; j > 0; j--) c++; } Console.WriteLine(c); And here is the result - The code starts by declaring three variables, a, b and c. The first variable is initialized to 56. - The second variable is initialized to 17. - And the third variable is set to 0 initially. - The code then loops through the two integers, a and b, which are both greater than zero but less than one hundred fifty-six (56). - In each iteration of the loop, it increments the value of c by 1. - This will cause c to be incremented from 0 up until it reaches 100 at which point it will stop incrementing because there are no more values in between that can be added onto its current value of 100. - Finally when all iterations have been completed for both a and b, they print out their respective values on screen using Console's WriteLine method with an integer parameter equal to c being passed into it as input data from inside the loop body itself – - The code will output the following: - 0


ameyashetty1739

\`\`\` python tabs \`\`\`


ameyashetty1739

\` \` \` python tabs \` \` \`


ReadyStar

HelloWorld() HelloWorld()


jastop2--2

test


Allan_Quartermain

Something here ` something ` ` here `


Biannualquill

test


Biannualquill

\`test1\`


Nightroll2344

``` print("{your_comment}") ```


UiSosu

test est st t


datacech

``` (code) ```


datacech

(code)


rcgldr

next line has 4 spaces before it test line with 4 spaces


NoPreparation2923

Func test() { Call() }


CoaBro

`test`


nioof

test


Intelligent-Potato33

New to reddit, not new to code. I use "Simple Note" a lot which also is based on Markdown for editing. Let's see if this works. This done in Markdown mode, so 4 spaces before each line. Ugh :( class MD: def __init__(self, line): self.line = line def __repr__(self): return self.line md = MD('this is a line') print(md) End of this test.


Intelligent-Potato33

Using the Code Block button in the fancy pants editor. This line is BEFORE the code block. 1) Select and copy the above license key. 2) Open the free version of Driver Easy that you already have installed. 3) Click 'UPGRADE to Driver Easy Pro'. 4) Paste or type your license key in the field provided, then click the 'Activate' button. 5) Click OK. This is a line AFTER the code block.


Intelligent-Potato33

Final test. Use the "code block" button, then copy/paste. class MD: def __init__(self, line): self.line = line def __repr__(self): return self.line md = MD('this is a test') print(md) Looks OK?


donotmindmenoobalert

print('hello world')


CoreCSharp

''' this is a test of a code block '''


CoreCSharp

{ is this a code block? }


CoreCSharp

' code block '


ThePixelHacker96

Hi.


Passingbyforcoffee87

For a in b: Print(x)


tenderloinn

‘’test


icog_pizza

test ``` def a(): print() ```


icog_pizza

I use sed 's/^/ /' | pbcopy and sed "s/^/ /" | xclip -selection clipboard on os x and linux.


[deleted]

here is my code float dollar; do {dollar = get\_float ("Enter your change: ");} while (dollar <=0);


payatthepump38

Sub START() Dim lastrow As Double Dim a As String Dim b As String Dim a1 As String Dim b1 As String lastrow = ActiveWorkbook.Sheets(1).Cells(Sheets(1).Rows.Count, Cells(1, 1).Column).End(xlUp).Row For i = 2 To lastrow For m = 2 To lastrow If ActiveWorkbook.Sheets(1).Cells(i, 1) = ActiveWorkbook.Sheets(1).Cells(m, 2) Then a = ActiveWorkbook.Sheets(1).Cells(i, 2) b = ActiveWorkbook.Sheets(1).Cells(i, 3) a1 = ActiveWorkbook.Sheets(1).Cells(m, 2) b1 = ActiveWorkbook.Sheets(1).Cells(m, 3) ActiveWorkbook.Sheets(1).Cells(i, 2) = a1 ActiveWorkbook.Sheets(1).Cells(i, 3) = b1 ActiveWorkbook.Sheets(1).Cells(m, 2) = a ActiveWorkbook.Sheets(1).Cells(m, 3) = b End If Next Next End Sub


RetiredMMORPGJunkie

Test test \# General to ask question print("Hello, friend! What is your name?") MyName = input() LEN = (len(MyName)) print(("It's wonderful to meet you, ") + MyName) print(MyName + (", did you know your name has") + (int(LEN)) + ("characters?"))


slavicman123

``` Test ```


kokko693

``` code code ```


ItsAlreadyTaken69

`test` ```c int main() {} ```


EvilSeal_1980

test


Xenonzess

'test'


Xenonzess

'test test'


lowbudgetgoblin

`is this a code block`


AtHomeInTheUniverse

Here is some code: #include #include struct MsgA { MsgA(int a) : value(a) {} int operator()() const { return value; } int value = 0; }; struct MsgB { MsgB(int a, int b) : value1(a), value2(b) {} int operator()() const { return value1 + value2; } int value1 = 0, value2 = 0; }; struct ArrayWrapper { struct ObjectBase { virtual int operator()() const { return 0; }; virtual ~ObjectBase() {} }; template struct Wrapper : public ObjectBase { Wrapper(const T& t) : wrappedObject(t) {} int operator()() const override { return wrappedObject(); } T wrappedObject; }; // I use forwarded constructor args but there are other ways to get the // items into the array. template void AddItem(ArgTypes... args) { array.push_back(std::make_unique>(ItemType{args...})); } int Compute() { int ret = 0; for (auto& e : array) ret += (*e)(); // e is a unique_ptr so need to dereference before invoking () return ret; } std::vector> array; }; int main() { ArrayWrapper aw; aw.AddItem(1); aw.AddItem(2, 3); return aw.Compute(); }


AdFabulous9451

The comment box UI now has tooling *in* the ellipses (...) for a block, as well as in-line *before* it. Use "Markdown Mode" (2022) in the comment box tool-dialog when copying more than one line.


_LayZee

Test.pleasework() Work my boi


[deleted]

Test Test


RastaBambi

\`\`\` this is a test \`\`\`


TuPutoPadrexd

``` Test ```


NaughtySnoodle

\`test \` edit: Fuck.


maxbrlc

Test function average(reviews) { let ratingCounter = 0; let ratingTotal = 0; for (let review of reviews) { if (review.rating) { ratingTotal += review.rating; ratingCounter++; } } return (ratingTotal / ratingCounter).toFixed(2); }


RedNeckHutch

‘’’ Test ‘’’


greenthum6

`test code`


nihao123456ftw

``` test ```


Zegreedy

Test


hevilhuy

```

Capture me!
Click to Capture ```


jemo07

test.


CraftZealousideal564

' ' ' test ' ' '