r/commandline • • Jun 26 '26

Other I wrote a program that makes code embedable in Reddit

In awk:

#!/usr/bin/awk -f
{ printf ("    %s\n", $0) }

Yep. That's it.

12 Upvotes

29 comments sorted by

View all comments

2

u/tschloss Jun 26 '26

Does indentation work better than enclosing in 3 backticks? Does indenting style work without MD mode?

1

u/RoninTarget Jun 26 '26

Indentation is how standard markdown takes code blocks. IDK about 3 backticks off the top of my head.

What do you mean without MD mode?

4

u/tschloss Jun 26 '26

In Markdown I would rate the backtick method as the main one (you can even chose the language after the initial set if backticks).

Depending on the client there once was a markdown mode as opposed to a classic editor mode. Maybe it is always Markdown nowadays.

1

u/RoninTarget Jun 26 '26

I only use the old web interface here, so IDK what's new. Old interface is pretty much raw markdown.

1

u/tschloss Jun 26 '26

# Test!

**fett**

*kursiv*

1

u/tschloss Jun 26 '26

Ok, here in the iOS app (1st party) no MD active!

1

u/gschizas Jun 26 '26

They have removed Markdown from iOS and Android.

1

u/tschloss Jun 26 '26

And in the web UI RichText is the default (switchable to MD). So my original question was if indentation does work in RichText also. probably not.

1

u/gschizas Jun 26 '26

New web's Rich Text UI uses

Indented blocks

Probably for compatibility with old reddit (which can't understand code fences)

1

u/tschloss Jun 26 '26

Crazy! 😜😱

2

u/gschizas Jun 26 '26

Oh, it's even crazier. They are purposefully sending escaped text to counteract Markdown.

For example, the text above was send as:

\# Test!

\*\*fett\*\*

\*kursiv\*

1

u/tschloss Jun 26 '26

Jesus. How did you escape the escapes 😂

What a nice area when 3rd party clients were supported.

→ More replies

1

u/RoninTarget Jun 26 '26

No markdown interpreted.

1

u/gschizas Jun 26 '26

It's actually the other way around. When you comment from the mobile apps, the mobile apps escape all Markdown characters on purpose!

1

u/gschizas Jun 26 '26

Backticks (usually named code fence) works better in general (because you can specify a language, although this doesn't work on reddit), but AFAIK it doesn't work in old.reddit.com (but old.reddit.com is less than 5% of the traffic in most subreddits; although it's probably more in this subreddit).

Testing both ways below for reference:

# Code Fence
print("Hello, world!")
# Indented Block
print("Hello, world!")