How to type code blocks

Markdown code block : Embed your code in 3 backticks, like this

```<optional language>
//your code here
```    

If you don’t know how to type a backtick, here are some related links :
How to type a backtick on windows
For mac users :
On qwerty keyboards it’s the key right to the left shift (along with the " key).
On azerty keyboards it’s the key over the right shift (along with the £ key).

This uses highlight.js, but uses a subset of the supported langages (following code block uses java).
If no language is specified java is used by default.

package jme3test.helloworld;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

/** Sample 1 - how to get started with the most simple JME 3 application.
 * Display a blue 3D cube and view from all sides by
 * moving the mouse and pressing the WASD keys. */
public class HelloJME3 extends SimpleApplication {

    public static void main(String[] args){
        HelloJME3 app = new HelloJME3();
        app.start(); // start the game
    }

    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1); // create cube shape
        Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
        Material mat = new Material(assetManager,
          "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
        mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
        geom.setMaterial(mat);                   // set the cube's material
        rootNode.attachChild(geom);              // make the cube appear in the scene
    }
}

Note that this is the preferred way of inserting code blocks.

Default code block : Paste the code, Select the code and hit the </> button in the tool bar. Alternatively you can indent each line of code by 4 space.

package jme3test.helloworld;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

/** Sample 1 - how to get started with the most simple JME 3 application.
 * Display a blue 3D cube and view from all sides by
 * moving the mouse and pressing the WASD keys. */
public class HelloJME3 extends SimpleApplication {

    public static void main(String[] args){
        HelloJME3 app = new HelloJME3();
        app.start(); // start the game
    }

    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1); // create cube shape
        Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
        Material mat = new Material(assetManager,
          "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
        mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
        geom.setMaterial(mat);                   // set the cube's material
        rootNode.attachChild(geom);              // make the cube appear in the scene
    }
}


**Github link :** You can also just put a github link to a code file, and a preview is displayed (you can't scroll so that's more aesthetic than useful) ; like this :
7 Likes

@nehon you should edit your sample to use ` instead of '.
you can embed ` x3 in ` x3

```<optional language>
//your code here

(for github users, it's the same syntax)
1 Like

Thanks a lot. It’s easier to understand like this.

1 Like

mhhh, i did type 3 backticks…
I didn’t realized they were shown as '.
Thanks for the tips :wink: I edited the post

1 Like

You can scroll the initial view by giving the URL a line number, like so:

https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-examples/src/main/java/jme3test/helloworld/HelloJME3.java#L30

Additionally, if you don’t want highlight.js but don’t want to indent your text, this works too:

```text
public class Main {}
```

turns into:

public class Main {}
3 Likes

Nice of you to stop by @riking :smile:

Thanks for the tip. Seems it wasn’t prepared for a dark theme though.

2 Likes

hey nice! thanks for the addition

1 Like

Is it just on my side, or is the “github code with line number” unreadable because of the coloring?

Thats the only code block i am having that issue however…

1 Like

Nope it’s not only on your side, I still need to tweak the style of github code blocks so that it fits in our dark theme

2 Likes

Should be better now

2 Likes

good only for github users :thinking:

…or JME forum users. Else I have no idea what you are talking about.

I will use this when I send the topic next time.

´´´ my code test
´´´

1 Like

1 Like

Uhm… where is it again?

https://m.media-amazon.com/images/I/718p2XNP-BL.AC_SL1500.jpg

Just trolling… but the forum trolled me in return, as I can’t post an image url with a “.” within it… oh well.
If you copy and paste the url above you’ll see an italian layout (which is missing the key in question).

I guess Italians are not allowed to type code blocks. It must be impossible.

1 Like

Simply use the code </> button of the text format editor toolbar :slightly_smiling_face:

Yes, I was being facetious. Obviously, Italians find a way to post code here.

Someone was struggling to find the right key for the tick mark so I showed them where it would normally be. At which point they can evaluate if they have that key on their keyboard or not.

Your response is the most useful one if they find that they do not have that key. I think when this topic was posted the </> button was unreliable. (perhaps even non-existent)

1 Like