Forum Code Formatting and Syntax Highlighting

To format code in this forum you need to surround the code with three backticks (```). For example, typing this...

```
fn main() {
    println!()
}
```

...will be rendered as highlighted Rust code, like so:

fn main() {
    println!()
}

You can also tell the forum software which language you're using by adding the language after the opening backticks.

```cpp
#include <iostream>
int main() {
  std::cout << "Hello World!";
}
```

Will appear with highlighting as:

#include <iostream>
int main() {
  std::cout << "Hello World!";
}

The currently supported languages include: apache, bash, cs, cpp, css, coffeescript, diff, xml, http, ini, json, java, javascript, makefile, markdown, nginx, objectivec, ruby, perl, php, python, sql, handlebars, rust and dust. Others may be added in the future.

It's also possible to add plain text by using text as the language:

```text
Error 365: Invalid command.
See help for a list of valid commands.
```

This will be rendered without any highlighting:

Error 365: Invalid command.
See help for a list of valid commands.

If your keyboard layout does not have the ` key, you can also use a ~.

~~~
fn main() {
    println!()
}
~~~

...will be rendered as highlighted Rust code, like so:

fn main() {
    println!()
}
44 Likes
Remove an element from the vector
Error in Format!
Help with multithreading - x/y axis manipulation
How to print value of a pointer
How to call a raw function pointer as a struct member wrapped by option
How to parse reqwest::blocking::response json to a struct
[Solved] Escape Quotes and Back Slash in Process Command Arguments
How to print two user input in a single line?
Unable to read or update hashMap values
Conflicting implementations
Input shows enter ./n
Why "move occurs"
Converting an image into a 2D matrix
Cannot infer type for type parameter `S` declared on the function
Passing Rust Vecs to functions
Structs,Traits,Associated Types and Inheritance
Mongodb(1.2.0) Crate : Compile Error when trying to use sync feature or async-std-runtime
Is posible egui change fonts to japanese ? How?
This code is extremely erroneous
Help with Mutex on fst
Function return a vector of shared ghost cell
How to implement trait for uom::si:Quantity
Explain why its failure
C Variadic functions in rust macro showing error
Implementing hash for a set datatype (i.e. multiple representations for Equal things)
String concatenation on variable assignment
Lifetime issue with deserialization
Python to Rust Code converter
Read unknown number of lines
Trait objects without an explicit `dyn` are deprecated
Rust Serialize and protocol buffer
Assert_eq in a for loop
Diesel Problem when loading
I'm new and i need help with code
`std::convert::From<mime::Mime>` is implemented for `&mut str`, but not for `&str`
Store a reference
Cannot deserialize with double quotes in the header
Rust Postgres Interval DataType Insert Problem
How to build C static library into a rust crate for no_std environmrnt
In a struct why must I use &str and a lifetime
Newbie: Why the commented line stops the snippet from compiling?
Converting Ruby to Rust JSON Parsing
Confused on errors while going through option1.rs rustling
Issue related to use of break statement with Ok variant
Help: Cloning string in the getter
Add extra infomation to Enum
Taking input from scv file
Use statements inside functions
But data from `x` flows into `x` here
Unmatched pointer value of a string when ownership is passed on
How to get hashmap key values
Problem with installing(windows)
Parse two errors in async function with reqwest
Zero initialize a large complex struct as global without code overhead
Why am I not allowed to copy part of a list filled with i32 to another variable?
Pinned topics and categories
How to compare variables of two types without type conversion or type casting using if statement
Confusion as a new rustacean
Cannot use `self....` because it was mutably borrowed
Immutable borrow when using .get on hashmap
Macro failed to resolve: use of undeclared crate or module
A lifetime problem
Calling for method "poll_next()" on a ClientSStreamReceiver gives error: "method not found"
Modify one field of type Option<serde_json::Value> in a struct
Deserialize JSON array of structs without element types using serde
Explain this code!
Problem sharing futures across threads when call from warp filter
Why can't I use the value in the vector for comparative operation?
If program leave loop, does program loses ownership of the variable?
Reference vector element
Assignment to single dim or 0-dim ndarray
Passing channels to threads
Serializing issue with primitive_types::u256 in a struct
What is different between &mut self and mut self?
[Beginner] - Struct Logic for Card Game
Postgresql performance
Problem calling midi windows api using winapi/winmm for extern
Abstracting serialization of specific state types
Help with read-write data from TCP server-to server (also converting)
Passing struct containing references as argument to an async function
How to read a connection for a serial?
Help about RefCell
Problem with lifetimes in Rc<RefCell<T>>
Problem with OpenOptions and write_all()
Temporary Value Dropped While Borrowed Using into_iter
Function definition with generic struct
Parse multiple input based on jsonfile with lettre
Practicing match and enum functions
How to collect string of input into array?
Rust-qt project compiling issue
Here i have skipped 7 line but now i want to get result from that result which i have skipped. I want to get 1st line from it but i can not get it then how can i get this first line?
Snmp recoverable error handling
Reading FITS files from subdirectories
Retrieving error from Result<T, Err(e)>
Hyper example proxy with rustls
1) convenient passing arguments to println!; 2) difference between slice and &str
One line conditionals
[Solved] Rust thread errors
What does the word "s" mean?
Driver compilation Issue
alloc::sync::Arc - reference counting stymied by closure?
Debug serialization problem?
How use cors in actix-web
Fix the unsafe blocks, Help!
Intresting how memory work for tuple.Please help
Fibonacci sequence (beginner asking for help)
Write_all and read using framed ... Not working Sending file over the network
Compilation error
Absolutely Rust newbie here! Please suggest me how to improve this simple program
Integrate HashMap into struct with methods
Value borrowed after move - how to get the value from inside a struct
thiserror::Error into Box<dyn std::error::Error + Send + Sync>
Trying to configure a USART peripheral
How to remove duplication in a vector in rust
Trying to understand moving ownership of vectors to funcs
Please help! having some problem
Rust book chapter 8 add employee exercise
A question about Associated types
Diesel : how to implement generic functions for CRUD operations on any table type?
Explain filter method
Pls Turn this code into async with futures
New to Rust...Getting an error. Pls help
How to get "message" field out of std::io::error
Unsafe related question
Sqlx only accept string literal, how to use variable?
Lifetime params for more complex function returns
How do i solve this issue, can't explain the issue properly
Using enum in different modules
Rust + Intel Fortran LIB
Variable value readable but not mutable (scope issue)
Reading a File with Struct, Trait and Impl
The Prototype Pattern and Rust
Implement static's trie-tree?
Not able to print captured variable to output
Dht11 and pico - combo
Cannot compile my code
How to deal with response? (web site)
help,Write a program in Rust to read a CSV file and create two output CSV files – one file with odd rows and the other file with even rows from the input file
Variable value readable but not mutable (scope issue)
Address of associated constant
Where to put the trait-definition
C++ converted to Rust, compiled ok but got a bad result. Which step is wrong?
C++ converted to Rust, compiled ok but got a bad result. Which step is wrong?
Guessing_Game Compile Issue
Loops and Pointers - *num and num are the same
What is the difference between impl<T> and impl<T: Config>
Please help me get rayon--struggling with trait implementations--to work in my rust-bio bioinformatics tool Rust implementation
How do I run the simple.rs gimli example?
Pass function closure to thread
How do I run the simple.rs gimli example?
I want to break out of loop when 0 occurs 4 times or 1 occurs 3 times (baseball balls and strikes)

Seems like pinning this thread would be fine?

10 Likes

This is part of "markdown", a standard text formatting syntax not unique to Github. These days most implementations I know of are using the CommonMark spec with some extentions. Here are some links:

I've also personally used ```s and other bits of markdown on StackOverflow, Slack and Discord, so it's pretty close to universal.

8 Likes

Since this has now been pinned (thanks!) I've removed the last note that lxrec is responding to, but I'll copy it here for posterity:

Summary

However this way of posting code isn't so obvious. It relies on a new user being aware of the github syntax and guessing that this forum uses the same syntax. I didn't when I first arrived and frequently new users post code that's hard to read because they aren't aware of how to format it for this forum's software.

Could there be somewhere that explains this placed where new users can see it?

I didn't realize that the syntax was now in the CommonMark spec. Thanks for the correction.

3 Likes