CodeFromFile Component

A built-in component to show source code from a file.

Example

Shows code from the file /content/docs/quickstart/docs-contributing/shortcodes/files/go-recover.go

package main

import "fmt"

func mayPanic() {
	panic("a problem")
}

func main() {
	defer func() {
		if r := recover(); r != nil {

			fmt.Println("Recovered. Error:\n", r)
		}
	}()
	
	mayPanic()

	fmt.Println("After mayPanic()")
}

Usage

{{< code-from-file file="/content/docs/quickstart/docs-contributing/shortcodes/files/go-recover.go" lang="go" >}}