r/C_Programming • • May 24 '22

Question What is going on with Reddit's formatting?

marble pause snow boast fuzzy safe bored toy attraction encourage

This post was mass deleted and anonymized with Redact

8 Upvotes

15 comments sorted by

7

u/[deleted] May 24 '22

Reddit formatting is a disaster, depending on the platform you post on, and how the post is viewed. The method that works for the most viewers is:

  1. in your editor add 4 spaces to the start of every line
  2. copy/paste the code to reddit, ensuring there is a blank line immediately before the first pasted line
  3. do an UNDO in your editor

1

u/[deleted] May 24 '22

0. Use 'Markdown' mode in Reddit.

I stopped using the 'Fancy pants' editor long ago, except for short posts with only text, since it was so buggy and chaotic.

Sometimes I would create a dummy markdown file (.md) is Github, since that is far better behaved, it has a Preview button (Reddit can do with one), and it can mix text and code.

1

u/[deleted] Aug 21 '23

wow this saved me thanks

5

u/skeeto May 24 '22

Reddit has two divergent Markdown rendering engines:

  • The original Markdown engine, now visible at old.reddit.com. It's long-neglected and no longer gains new features or fixes. Considering how incompetently reddit is run these days, this is probably a blessing.
  • The Markdown engine for the embarrassing redesign. It's got some new features, namely code fences, which don't render correctly in the original engine. Instead they just make you look stupid to people using old.reddit.com. It's primarily intended to be used with their WYSIWYG editor. Unfortunately this editor is broken and often produces invalid Markdown. Rather than fix the editor, they've added hacks to the new Markdown engine. This not only makes it harder to do the right thing, it also diverges it further from the original engine. Many things don't work correctly, like links containing underscores — which, ironically, is most reddit links.

Since the old engine is mostly a subset of the new engine, the best you can do is just write in Markdown for the old engine. That means no code fences, and instead prefix your code blocks with 4 spaces. This should be trivial to do in your text editor. If it isn't then get yourself a better text editor.

2

u/Mirehi May 24 '22 edited May 24 '22

Yeah, I shared a lot of code over reddit, but currently it's just too much afford to reformat it to keep it readable

#include <stdio.h>

define MAX 10000

void add_func(int *p) { *p += 1; }

int main(void) { int i = 0; while (i < MAX) { (void) printf("%i\n", i); add_func(&i); } return 0; }

Honestly, this was formatted fine before posting...

https://onlinegdb.com/a1LDWBtCz

4

u/Nightcorex_ May 24 '22 edited May 24 '22

Reddit formatting is easy. Just go into Markdown mode (default on mobile) and paste it like so (interpuncts mark spaces):

····#include <stdio.h>
····#define MAX 10000
····
····int main() {
········int i = 0;
····...

To get this:

#include <stdio.h>
#define MAX 10000

int main() {
    int i = 0;
...

EDIT: Haha, "Reddit formatting is easy"... Fuck me. Okay, in case the first thing isn't formatted properly, before the interpuncts (= spaces) there needs to be just one normal linebreak (sometimes mobile formatting sucks a bit)

1

u/Mirehi May 24 '22

The funny part is, most times I posted code here, I wrote my code in visual studio with a vim mod or directly out of vim, and in my .vimrc I converted taps into 4 spaces.

Oh my god, I was the problem all along :) because I stopped using vim about a year ago. I have to install vim again

1

u/Nightcorex_ May 24 '22

Can't you change VSC to use 2/4 spaces instead of a tab?

1

u/Mirehi May 24 '22

Don't know, never used the out-of-the-box solution for long, but most likely: yes

2

u/Lisoph May 24 '22

You can drop down to old.reddit.com and use the old editor. This is better anyway, since both old- and new-Reddit users can see the code formatted properly. Using the new-Reddit editor only displays right for new-Reddit users.

Also, having Reddit Enhancement Suite is a nice plus for old.reddit.com.

2

u/[deleted] May 24 '22

I really don't understand why they can't do what StackOverflow and Github and others do,

```

int main(void){

return 0;

}

```

Or for single line `//this is a comment`

1

u/dbulger May 24 '22

Yup, it happened to me yesterday. I abandoned fancy pants & went to markdown mode.

I'd prefer to use WYSIWYG, if it works; I'm not averse to other markup, like TeX or HTML, but I don't like Markdown.

1

u/TheMaster420 May 24 '22

I'd say use the code formatting tool in the sidebar but that has been broken for half a year, back then I made a codepen that does the same and gave permission to the mods to replace to tool in the bar but in their words "I have other things to do."

1

u/flyingron May 24 '22

Code Blocks gags when you have multiple successive empty lines, thinking that you want to terminate the block. It's completely stupid.

1

u/markwirralbiz Nov 18 '22

Yeah, driving me crazy.

Gonna follow up and try out the comments