Code blocks variants
Since v4.2.0, Terminal Theme uses Chroma as syntax highlighter. As Hugo documentation refers: “it is built in Go and is really, really fast”.
Below you can see many basic presentations of the code blocks you can use depending on your needs. Except the {{ < code > }}
shortcode example, all other blocks are generated based on the configuration you can learn about from the official Hugo docs.
Examples:#
Raw block with no specified language (and no syntax highlighting)#
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example HTML5 Document</title>
</head>
<body>
<p>Test</p>
</body>
</html>
With specified language#
Line highlighting#
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example HTML5 Document</title>
</head>
<body>
<p>Test</p>
</body>
</html>
Line highlighting / table line numbers#
|
|
Line highlighting / inline line numbers#
1<!doctype html>
2<html lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <title>Example HTML5 Document</title>
6 </head>
7 <body>
8 <p>Test</p>
9 </body>
10</html>
Hugo’s internal {{ < highlight > }}
shortcode#
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example HTML5 Document</title>
</head>
<body>
<p>Test</p>
</body>
</html>
Custom built-in {{ < code > }}
shortcode#
Hey, this is a code block title
|
|
Programming languages:#
A#
WRITE 'Hello, World!'.
package {
public class HelloWorld {
public static function main():void {
trace("Hello, World!");
}
}
}
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put_Line("Hello, World!");
end Hello;
B#
echo "Hello, World!"
+[----->+++<]>.++++++++++++..+++.>++++++[->+++++++<]>+.------------.---.+++++.
C#
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
D#
import std.stdio;
void main() {
writeln("Hello, World!");
}
E#
IO.puts "Hello, World!"
-module(hello).
-export([world/0]).
world() -> io:format("Hello, World!~n").
F#
printfn "Hello, World!"
G#
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
H#
main = putStrLn "Hello, World!"
J#
var x, y, z; // Declare 3 variables
x = 5; // Assign the value 5 to x
y = 6; // Assign the value 6 to y
z = x + y; // Assign the sum of x and y to z
document.getElementById("demo").innerHTML = "The value of z is " + z + ".";
function Video({ video }) {
return (
<div>
<Thumbnail video={video} />
<a href={video.url}>
<h3>{video.title}</h3>
<p>{video.description}</p>
</a>
<LikeButton video={video} />
</div>
);
}
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
K#
fun main() {
println("Hello, World!")
}
L#
print("Hello, World!")
M#
disp('Hello, World!')
N#
echo "Hello, World!"
O#
#import <Foundation/Foundation.h>
int main() {
@autoreleasepool {
NSLog(@"Hello, World!");
}
return 0;
}
P#
print("Hello, World!\n");
<?php echo "Hello, World!"; ?>
print("Hello, World!")
R#
cat("Hello, World!\n")
puts "Hello, World!"
fn main() {
println!("Hello, World!");
}
S#
object HelloWorld extends App {
println("Hello, World!")
}
T#
console.log("Hello, World!");
V#
fn main() {
println('Hello, World!')
}
Z#
const std = @import("std");
pub fn main() !void {
std.debug.print("Hello, World!\n", .{});
}
Read other posts