code

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Bash       = "bash"
	Elixir     = "elixir"
	Go         = "go"
	Javascript = "javascript"
	Lua        = "lua"
	Perl       = "perl"
	Python     = "python"
	Ruby       = "ruby"
	Rust       = "rust"
	Java       = "java"
)

Supported Languages

View Source
const (
	// ExitCodeInternalError represents the exit code in which the code
	// executing the code didn't work.
	ExitCodeInternalError = -1
)

Variables

View Source
var (
	// ErrParse is the returned error when we cannot parse the code block (i.e.
	// there is no code block on the current slide) or the code block is
	// incorrectly written.
	ErrParse = errors.New("Error: could not parse code block")
)
View Source
var Languages = map[string]Language{
	Bash: {
		Extension: "sh",
		Commands:  cmds{{"bash", "<file>"}},
	},
	Elixir: {
		Extension: "exs",
		Commands:  cmds{{"elixir", "<file>"}},
	},
	Go: {
		Extension: "go",
		Commands:  cmds{{"go", "run", "<file>"}},
	},
	Javascript: {
		Extension: "js",
		Commands:  cmds{{"node", "<file>"}},
	},
	Lua: {
		Extension: "lua",
		Commands:  cmds{{"lua", "<file>"}},
	},
	Ruby: {
		Extension: "rb",
		Commands:  cmds{{"ruby", "<file>"}},
	},
	Python: {
		Extension: "py",
		Commands:  cmds{{"python", "<file>"}},
	},
	Perl: {
		Extension: "pl",
		Commands:  cmds{{"perl", "<file>"}},
	},
	Rust: {
		Extension: "rs",
		Commands: cmds{

			{"rustc", "<file>", "-o", "<path>/<name>.run"},

			{"<path>/<name>.run"},
		},
	},
	Java: {
		Extension: "java",
		Commands:  cmds{{"java", "<file>"}},
	},
}

Languages is a map of supported languages with their extensions and commands to run to execute the program.

Functions

func HideComments added in v0.9.0

func HideComments(content string) string

HideComments removes all comments from the given content.

func RemoveComments added in v0.9.0

func RemoveComments(content string) string

RemoveComments strips all the comments from the given content. This is useful for when we want to actually use the content of the comments.

Types

type Block

type Block struct {
	Code     string
	Language string
}

Block represents a code block.

func Parse

func Parse(markdown string) ([]Block, error)

Parse takes a block of markdown and returns an array of Block's with code and associated languages

type Language

type Language struct {
	// Extension represents the file extension used by this language.
	Extension string
	// Commands  [][]string // placeholders: <name> file name (without
	// extension), <file> file name, <path> path without file name
	Commands cmds
}

Language represents a programming language with it Extension and Commands to execute its programs.

type Result

type Result struct {
	Out           string
	ExitCode      int
	ExecutionTime time.Duration
}

Result represents the output for an executed code block.

func Execute

func Execute(code Block) Result

Execute takes a code.Block and returns the output of the executed code

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL