Files
slides/examples/code_blocks.md
Mahmoud Fathi ebc2ab70bf feat: add support for java code execution
As of Java 11 a single file can be launched without explicitly
compiling, packaging and running the file in different steps.
In other words single-file source-code programs can be executed
with "java Program.java", where "Program.java" is the name of
the file to be executed.
2022-09-04 16:25:09 -04:00

1.4 KiB

Code blocks

Slides allows you to execute code blocks directly inside your slides!

Just press ctrl+e and the result of the code block will be displayed as virtual text in your slides.

Currently supported languages:

  • bash
  • elixir
  • go
  • javascript
  • python
  • ruby
  • perl
  • rust
  • java

Bash

ls

Elixir

IO.puts "Hello, world!"

Go

Use /// to hide verbose code but still allow the ability to execute it.

If you press y to copy (yank) this code block it will return the full snippet.

And, if you press ctrl+e it will run the program without error, even though what is being displayed is not a valid go program because we have commented out some boilerplate to focus on the important parts.

///package main
///
import "fmt"
///
///func main() {
fmt.Println("Hello, world!")
///}

Javascript

console.log("Hello, world!")

Lua

print("Hello, World!")

Python

print("Hello, world!")

Ruby

puts "Hello, world!"

Perl

print ("hello, world");

Rust

fn main() {
    println!("Hello, world!");
}

Java

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}