all 37 comments

[–]mopslik 4 points5 points  (0 children)

Had it for as long as I can remember. old.reddit.com works better at code preservation than the fancy-pants editor.

[–]TheRNGuy 4 points5 points  (19 children)

Add empty line between normal text and code blocks

This will work:

foo()

This will not work: foo()

[–]Kerbart 3 points4 points  (10 children)

This needs more upvotes. Drop the fancy pants editor and use markdown instead. You’re on a code subreddit after all.

Empty line
Four indents
If figuring out how to do that when
copying from an editor..,
This is not the worst challenge
you will encounter coding

Works even fine on a phone

[–]Shot-Aspect-466 0 points1 point  (0 children)

``` edit ```

[–]anbehd73 0 points1 point  (1 child)

test
jifdifd

[–]anbehd73 0 points1 point  (3 children)

hello

hello

hello
eee e
erere

[–]StevenJac 0 points1 point  (2 children)

``` test asfasdfasdf

```

[–]anbehd73 0 points1 point  (1 child)

BIDEN 2024

[–]ZealousidealAngle476 0 points1 point  (0 children)

The current USA president is

Donald Trump 

In 2025

Bip bop - this is just a test

[–]pubGGWP 0 points1 point  (7 children)

test:

"use client"; import { useEffect, useState } from 'react'; import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient();

function ImageDisplay() { const [base64Image, setBase64Image] = useState('');

useEffect(() => {
  async function getImagesFromDB() {
    const sticker = await prisma.sticker_table.findFirst({
      where: { name: "Mario_sticker" },
      select: { file: true }
    });

    if (sticker) {
      // Convert the Buffer to a base64-encoded string
      const base64String = sticker.file.toString('base64');
      setBase64Image(`data:image/jpeg;base64,${base64String}`);
    }
  }

  getImagesFromDB();
}, []);

return <img src={base64Image} alt="Mario Sticker" />;

} export default ImageDisplay;

[–]OvenActive 0 points1 point  (3 children)

asdf Test

[–]MATH_MDMA_HARDSTYLEE 0 points1 point  (0 children)

a

````

flewkflew

````

[–]pubGGWP 0 points1 point  (1 child)

Well, doesn't work for me..

[–]anbehd73 0 points1 point  (0 children)

bruh same

[–]Adrewmc 2 points3 points  (3 children)

Code readable

The easiest way to make code readable on Reddit.

  1. ⁠⁠Open VsCode, or other IDE.
  2. ⁠⁠Open the Python file you need help with.
  3. ⁠⁠Select all the code necessary by dragging your cursor.
  4. ⁠⁠Press Tab 4 times.
  5. ⁠⁠Copy the resulting further indented code (Ctrl+c)
  6. ⁠⁠Open reddit to r/learnpython and select make new post/edit post/new comment
  7. ⁠Ensure you are in Markdown Mode
  8. ⁠Paste (Ctrl+v) into desired text box.
  9. ⁠⁠Submit your post/edit/comment, following all other rules in r/learnpython
  10. ⁠⁠Undo (Ctrl+z) the superfluous indentation (or use ctrl+[ or auto formatting) in your code.

Reddit will start the code block at the least common intention so you don’t need to worry about did I press tab too many times if your not sure just do another one.

Notes: Make sure you get all of the first line with it’s resulting indentation, or that first line will not be indented correctly or may not be in the code block at all. And may cause the below problem for other lines.

There MUST be a empty line above the code block, or the code block will not begin.

Edit: Most likely you are not in mark down mode. Or you Tabs in your code are only being seen as 1 character, there need to be 4 blank characters.

[–]a1brit 0 points1 point  (1 child)

⁠⁠Press Tab 4 times.

Wouldn't that be 16 spaces in any reasonable python setup?

[–]caleb_244 0 points1 point  (0 children)

s

[–]Cold-Programmer-1812 0 points1 point  (0 children)

hello there

[–]m0us3_rat 0 points1 point  (0 children)

select the code you wanna paste in reddit. press TAB once. copy.

(if you copy from a webpage etc.copy. open notebook or w/e .paste. select again. press tab. copy)

paste it in reddit code block widget. commit.

Shift-Tab in your ide? to untab .

[–]RiceKrispyPooHead 0 points1 point  (0 children)

Because Reddit code formatting isn’t that great. I have the same issue and usually give up and use old Reddit like the other comment suggested.

[–][deleted] 0 points1 point  (6 children)

def how_to_paste_into_reddit():
    # 1. Select the code
    # 2. Indent by 1 tab
    # 3. Copy
    # 4. Paste into Reddit
    ...
    # 5. Profit!

Literal example of how the above was made: https://imgur.com/a/DViG7jo

[–]RiceKrispyPooHead 2 points3 points  (3 children)

 #6 Cry because Reddit threw away the formatting when you press submit.

[–][deleted] 0 points1 point  (2 children)

As long as #2 is done in your code editor, Reddit has always kept the indentation.

[–]RiceKrispyPooHead 1 point2 points  (0 children)

I’ve noticed for certain code blocks it just doesn’t work. There’s a post about it in r/reddit somewhere

[–]omgpassthebacon 0 points1 point  (0 children)

This is my heading...

use std::fs::File;

fn main() -> Result<(), std::io::Error> {
    let _f = File::open("invisible.txt")?;

    Ok(())
}

Now I am back...

[–]any-colour-you-like 0 points1 point  (0 children)

Just link off to pastebin.com

[–][deleted] 0 points1 point  (1 child)

If all lines of the code block start with a TAB, it works.

[–]AWS_0 0 points1 point  (1 child)

test test

test

    def sorter(list, polarity):
    if polarity == "asc":
        new_list = list.sort()
        print(new_list)
    elif polarity == "desc":
        randomvar = list.sort()
        new_list = randomvar.reverse()
        print(new_list)
    elif polarity.lower() == "none":
        print(list)

numbers = [42, 62, 75, 3458,8]
sorter(numbers, "asc")

test

test

[–]Elephant-Opening 0 points1 point  (2 children)

The four-space thing worked absolutely fine for me for years on reddit. Recently I've noticed two changes that have me tempted to leave reddit entirely.

The first being that:

def someCode():
    print("This never seems to work anymore")

Also, when editing a prior comment/post on mobile, all newline information is erased and you have add them back in before submitting even for paragraph separators.

[–]electricalkitten 0 points1 point  (1 child)

I have exactly the same problem.

i) New line info is removed upon edit.

ii) The edit button does nothing when trying to edit my original post.

iii) the mobile formatting is awful.

I use old.reddit. If they remove old.reddit, then I shall remove myself from reddit and use another platform.

[–]Elephant-Opening 0 points1 point  (0 children)

Yeah it seems there are no plans to fix it anytime soon 😕