Syntax highlighting

So, I was just writing a post, when it came to mind that there isn’t any Syntax highlighting here. Afterall, on this forum there are a lot of people posting code and discussing it, Syntax highlighting would IMO be a truley amazing thing xD

5 Likes

And it’s preeeeeettyyyyyy :blush: Helpful too!

1 Like

http://tohtml.com/

Turns code into html code for embedding.

Eg.

/* HelloWorld.java
 */

public class HelloWorld
{
	public static void main(String[] args) {
		System.out.println("Hello World!");
	}
}

That wont actually highlighting the syntax. It just seemed to format the tabs.

Yah, the colour codes are in there, but this forum doesn’t seam to be using them. So we relay just need the forum to suport html colour codes.

Which makes it not very efficient haha. Anyways I think syntax highlighting would be a good idea, but I think pasting huge lines of code would make threads messy. You could always use GitHub’s Gist system, or even pastebin with syntax highlighting.
eg. gist:1a7d14f9cc476a347a74 · GitHub (a random sponge class)

1 Like

We could implement the paste bin BB code using their API fairly easily, then they handle syntax highlighting for you.

ewww that mixed coding style :stuck_out_tongue:

4 Likes

Well implement it as you will, but pastebin’s API is one of the best to support syntax highlighting. Can be done in html, php, or like I said, BB. Oh, and javascript, all of witch should be able to be used inside posts, but cannot currently.

Right. I was joking in that reply. It would be nice if the forum would auto-format everything inside ticks. It already formats code, but highlighting would be sexy.

It seams to not support any text colour, not using bb or html, it just ignores the tags, I’d bet 'ya it’s a setting on the admin panel, weather or not to support coloured text.

Well there is some color.

/* 
    HelloWorld.java
 */
    public class HelloWorld
{
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
}
1 Like

Can we see sterilized code for that pls? (IYDK add a \ before each control chr)

hhhhnnnnnggggg! Yay!

Triple back tick then the language.
‘’‘Java
Code
‘’’
I used single quotes for I couldn’t find a way to escape the back ticks in code.

1 Like

Test for me:

/* 
    HelloWorld.java
 */
    public class HelloWorld
{
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
}

And here:
```Java
Code
```

Looks like this: (I escape the escapes)

\`\`\`Java
Code
\`\`\`

Test

public class Test
{
  static
  {
    System.out.println("woah");
    System.exit(0);
  }
}
def test():
    print 'python'
test()
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

(i dont actually know brainfuck – copied that one from wikipedia, but it highlights :D)

Thanks, @Twillen

Test C++/C:

#include <iostream>
 
using namespace std;
 
Int main(){
Cout << " Hello World" << endl;
Return 0;
}

I see the error of my way, I was tying to escape the the example in a tick code block.

 ```Java
```

4 space lead line syntax also works.

[code]

[/code]

This syntax seems to work as well

/* 
    HelloWorld.java
 */
    public class HelloWorld
{
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
}

Seems that it figured out the language in the [code] block, or just has one coloring.

I wonder if all of stackexcanges markdown works?

Well the URL mark down works.

Oh no… The two types of curly braces… I don’t think I can do it man!