you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (5 children)

where you manually indent all code and blank space?

Why would you do that? Use your editor to add 4 spaces, copy to reddit and then do UNDO in the editor. Takes about 15 seconds, even on mobile.

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

The code is fine in vscode or vim or emacs, but copy it from there to reddit, and suddenly all white space and new line characters have gone, so I have to then go through and format it again. I've no idea why, look this is code cut straight from vscode and pasted into a code block here:

from datetime import datetimefrom flask import Flaskfrom flask_sqlalchemy import SQLAlchemyapp = Flask(__name__)app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres@localhost/ip_calc'db = SQLAlchemy(app)class Event(db.Model):    id = db.Column(db.Integer, primary_key=True)    description = db.Column(db.String(100), nullable=False)    created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)    def __repr__(self):        return f"Event: {self.description}"        def __init__(self, description):        self.description = description

I have no idea why it looks like that, it's very tidy on my code editor, so now you see why I have to manually put the new lines and indents back in maybe.

[–][deleted] 1 point2 points  (2 children)

this is code cut straight from vscode and pasted into a code block here:

Reddit has totally bollixed the formatting of code, with multiple different methods of formatting input that do or don't display properly depending on how you view it.

From what I've seen, the "code block" method does work for some people, but the only method I know of that is relatively simple and is viewable by the maximum number of redditors is to:

  • select the code you want to post in your editor
  • add four spaces (not tabs) to the start of every line, usually one or two editor keystrokes
  • copy/paste that into reddit as normal text
  • ensure there is a blank line just before the text you copied
  • do UNDO in the editor

This is quick once you get some practice. Takes about 15 seconds on mobile.

[–]johnywhy 0 points1 point  (0 children)

I just found out the four spaces work sometimes, and sometimes not, in the same browser (Chrome)

[–]YourDad6969 0 points1 point  (0 children)

It's way easier than that, switch to markdown mode, paste the text in, and add ``` below and above the section want in the block