Examples¶
The content of a codefence is parsed the same
as the content of a .. code::
directive.
For example, the following:
```
Hello world!
```
Is rendered as:
Hello world!
Code fences support languages. The language keyword is passed as the optional
argument to the .. code::
directive. For example:
```cpp
int main(int argc, char** argv){
exit(0);
}
```
Is rendered as:
int main(int argc, char** argv){
exit(0);
}
Code fences can also be nested within indented structures, such as:
.. tip::
This code-fence is nested within an admonition.
```py
def hello_world():
print("hello world")
```
which is rendered as:
Tip
This code-fence is nested within an admonition.
def hello_world():
print("hello world")
However the whole point of using a code-fence is to avoid the indentation so I’m not sure why you’d want to do that.
There are two styles of codefence. You can either use triple-tick or triple-tilde. The examples thus-far have been triple-tick. Triple-tilda looks like this:
~~~py
def hello_codefence():
print("I am in a codefence!")
~~~
Which renders as:
def hello_codefence():
print("I am in a codefence!")