#documentation

Rust

Rust samples

This article provides some code samples in Rust.

Command line interface

Command arguments

cargo run foo bar baz "This string is a sentence"
1use std::env;
2
3// cargo run hello world
4
5fn main() {
6 let args: Vec<String> = env::args().collect();
7
8 // Retrieve first argument
9 let input = args[1].clone();
10
11 // Print all arguments
12 println!("{:?}", args); // ["target/debug/executable", "foo", "bar", "baz", "This string is a sentence"]
13}

Standard input

1use std::io;
2
3fn main() {
4 // empty string
5 let mut input = String::new();
6
7 // Collecting user input
8 println!("Enter your name: ");
9 io::stdin()
10 .read_line(&mut input)
11 .expect("Failed to read line");
12
13 println!("Received name: {}", input);
14}
15
Rust

Markdown

Sample article showcasing basic Markdown syntax and formatting for HTML elements.

Markdown logo

This article offers a sample of basic Markdown syntax that can be used in Zola content files, also it shows whether basic HTML elements are decorated with CSS in a Kita theme.

Headings

The following HTML <h1><h6> elements represent six levels of section headings. <h1> is the highest section level while <h6> is the lowest.

H1

H2

H3

H4

H5
H6

Paragraph

Xerum, quo qui aut unt expliquam qui dolut labo. Aque venitatiusda cum, voluptionse latur sitiae dolessi aut parist aut dollo enim qui voluptate ma dolestendit peritin re plis aut quas inctum laceat est volestemque commosa as cus endigna tectur, offic to cor sequas etum rerum idem sintibus eiur? Quianimin porecus evelectur, cum que nis nust voloribus ratem aut omnimi, sitatur? Quiatem. Nam, omnis sum am facea corem alique molestrunt et eos evelece arcillit ut aut eos eos nus, sin conecerem erum fuga. Ri oditatquam, ad quibus unda veliamenimin cusam et facea ipsamus es exerum sitate dolores editium rerore eost, temped molorro ratiae volorro te reribus dolorer sperchicium faceata tiustia prat.

Itatur? Quiatae cullecum rem ent aut odis in re eossequodi nonsequ idebis ne sapicia is sinveli squiatum, core et que aut hariosam ex eat.

Blockquotes

The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a footer or cite element, and optionally with in-line changes such as annotations and abbreviations.

Blockquote without attribution

Tiam, ad mint andaepu dandae nostion secatur sequo quae. Note that you can use Markdown syntax within a blockquote.

Blockquote with attribution

Don't communicate by sharing memory, share memory by communicating.
Rob Pike1

1

The above quote is excerpted from Rob Pike's talk during Gopherfest, November 18, 2015.

To create a link, enclose the link text in brackets and then follow it immediately with the URL in parentheses.

GitHub

To quickly turn a URL or email address into a link, enclose it in angle brackets.

https://github.com

Images

Markdown Guide

Tables

Tables aren't part of the core Markdown spec, but Zola supports supports them out-of-the-box.

NameAge
Bob27
Alice23

Inline Markdown within tables

ItalicsBoldCode
italicsboldcode

Code Blocks

Code block with backticks

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Example HTML5 Document</title>
  </head>
  <body>
    <p>Test</p>
  </body>
</html>

Code block indented with four spaces

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Example HTML5 Document</title>
</head>
<body>
  <p>Test</p>
</body>
</html>

List Types

Ordered List

  1. First item
  2. Second item
  3. Third item

Unordered List

  • List item
  • Another item
  • And another item

Nested list

  • Fruit
    • Apple
    • Orange
    • Banana
  • Dairy
    • Milk
    • Cheese

Other Elements — abbr, sub, sup, kbd, mark

GIF is a bitmap image format.

H2O

Xn + Yn = Zn

Press CTRL+ALT+Delete to end the session.

Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures.

Markdown

Zola Syntax Highlighting

Syntax Highlighting in Zola.

Zola comes with built-in syntax highlighting but you first need to enable it in the configuration.

Annotations

You can use additional annotations to customize how code blocks are displayed:

  • linenos to enable line numbering.
```rust,linenos
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
    println!("{}", bar);
    let baz = bar + 42;
    println!("{}", baz);
    println!("{}", baz * 3.14);
}
```
1use highlighter::highlight;
2use std::env;
3let code = "...";
4highlight(code);
5fn foo(bar: i32) {
6 println!("{}", bar);
7 let baz = bar + 42;
8 println!("{}", baz);
9 println!("{}", baz * 3.14);
10}
  • linenostart to specify the number for the first line (defaults to 1)
```rust,linenos,linenostart=20
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
    println!("{}", bar);
    let baz = bar + 42;
    println!("{}", baz);
    println!("{}", baz * 3.14);
}
```
20use highlighter::highlight;
21use std::env;
22let code = "...";
23highlight(code);
24fn foo(bar: i32) {
25 println!("{}", bar);
26 let baz = bar + 42;
27 println!("{}", baz);
28 println!("{}", baz * 3.14);
29}
  • hl_lines to highlight lines. You must specify a list of inclusive ranges of lines to highlight, separated by (whitespace). Ranges are 1-indexed and linenostart doesn't influence the values, it always refers to the codeblock line number.
```rust,hl_lines=1 3-5 9
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
    println!("{}", bar);
    let baz = bar + 42;
    println!("{}", baz);
    println!("{}", baz * 3.14);
}
```
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
    println!("{}", bar);
    let baz = bar + 42;
    println!("{}", baz);
    println!("{}", baz * 3.14);
}
  • hide_lines to hide lines. You must specify a list of inclusive ranges of lines to hide, separated by (whitespace). Ranges are 1-indexed.
```rust,hide_lines=1-2
use highlighter::highlight;
use std::env;
let code = "...";
highlight(code);
fn foo(bar: i32) {
    println!("{}", bar);
    let baz = bar + 42;
    println!("{}", baz);
    println!("{}", baz * 3.14);
}
```
let code = "...";
highlight(code);
fn foo(bar: i32) {
    println!("{}", bar);
    let baz = bar + 42;
    println!("{}", baz);
    println!("{}", baz * 3.14);
}
Zola Syntax Highlighting

Kita Shortcodes

The Kita theme shortcodes.

The Kita theme providers multiple shortcodes.

Never heard of shortcodes? See Zola documentation for more information.

Mermaid

To use Mermaid in your page, you have to set extra.mermaid = true in the frontmatter of page.

+++
title = "Your page title"

[extra]
mermaid = true
+++

Then you can use the mermaid() shortcodes like:

  </span><span>
</span><span>graph TD;
</span><span>A--&gt;B;
</span><span>A--&gt;C;
</span><span>B--&gt;D;
</span><span>C--&gt;D;
</span><span>
</span><span>

This will be rendered as:

  graph TD;
A-->B;
A-->C;
B-->D;
C-->D;

In addition, you can use code block inside mermaid() shortcodes and the code block will be ignored.

The code block prevents formatter from breaking mermaid's formatting.

  </span><span>
</span><span>```</span><span style="color:#bd93f9;">mermaid
</span><span>sequenceDiagram
</span><span>    participant Alice
</span><span>    participant Bob
</span><span>    Alice-&gt;&gt;John: Hello John, how are you?
</span><span>    loop Healthcheck
</span><span>        John-&gt;&gt;John: Fight against hypochondria
</span><span>    end
</span><span>    Note right of John: Rational thoughts &lt;br/&gt;prevail!
</span><span>    John--&gt;&gt;Alice: Great!
</span><span>    John-&gt;&gt;Bob: How about you?
</span><span>    Bob--&gt;&gt;John: Jolly good!
</span><span>```
</span><span>
</span><span>

This will be rendered as:

sequenceDiagram participant Alice participant Bob Alice->>John: Hello John, how are you? loop Healthcheck John->>John: Fight against hypochondria end Note right of John: Rational thoughts <br/>prevail! John-->>Alice: Great! John->>Bob: How about you? Bob-->>John: Jolly good!

Admonition

The admonition() shortcode displays a banner to help you put notice in your page.

You can use the admonition() shortcode like:

{% admonition(type="tip", title="tip") %}
The `tip` admonition.
{% end %}

The admonition shortcode has 12 different types:

note
note

The note admonition.

abstract
abstract

The abstract admonition.

info
info

The info admonition.

tip
tip

The tip admonition.

success
success

The success admonition.

question
question

The question admonition.

warning
warning

The warning admonition.

failure
failure

The failure admonition.

abstract
danger

The danger admonition.

bug
bug

The bug admonition.

example
example

The example admonition.

quote
quote

The quote admonition.

The gallery() shortcode is very simple html-only clickable picture gallery that displays all images from the page assets.

It's from Zola documentation

{{# gallery() #}}
Kita Shortcodes