codeblock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package codeblock wires the individual evaluators (php, vuego, exec, sqlite) into a single service used by the tour and docs servers. It exposes:

  • an HTTP handler for POST /api/codeblock/eval
  • a markdown handler that rewrites runnable code fences into widgets with a "Run" button and an "Output" area

Which evaluators are available is decided by Config, so each host (tour, docs) opts in to exactly the languages it wants to support.

Index

Constants

View Source
const (
	LangVuego = "vuego"
	LangPHP   = "php"
	LangExec  = "exec"
	LangSQL   = "sql"
)

Canonical language identifiers.

View Source
const EvalPath = "/api/codeblock/eval"

EvalPath is the HTTP path that the frontend posts evaluation requests to.

View Source
const ScriptPath = "/assets/codeblock.js"

ScriptPath is the URL the runnable widget loads its behaviour from.

Variables

This section is empty.

Functions

func Assets

func Assets() fs.FS

Assets returns the embedded static assets (codeblock.js) rooted so that "assets/codeblock.js" resolves. Hosts can overlay this into their content filesystem to have it served by an /assets/* file server.

func Canonical

func Canonical(language string) (string, bool)

Canonical resolves a fence info string to a canonical language identifier. It returns ("", false) when the language is unknown.

Types

type Config

type Config struct {
	EnablePHP    bool
	EnableVuego  bool
	EnableExec   bool
	EnableSQLite bool
}

Config selects which evaluators are enabled. Hosts define their own default (for example tour.DefaultConfig, docs.DefaultConfig) so evaluation is opt-in.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service evaluates code snippets for the enabled languages.

func New

func New(cfg Config, baseFS fs.FS, opts ...vuego.LoadOption) *Service

New builds a Service from cfg. baseFS supplies shared dependencies (components, layouts) for the vuego evaluator and may be nil; opts are vuego load options applied to vuego renders.

func (*Service) CodeBlockHandler

func (s *Service) CodeBlockHandler() markdown.Handler

CodeBlockHandler returns a markdown handler that rewrites runnable code fences (for enabled languages) into a widget with the original code, a Run button and an Output area. Unrecognized or disabled languages are left untouched.

func (*Service) Eval

Eval runs a single evaluation request and returns a response suitable for JSON encoding. Errors are reported in the response rather than returned.

func (*Service) Handler

func (s *Service) Handler() http.HandlerFunc

Handler returns an http.HandlerFunc serving POST /api/codeblock/eval.

func (*Service) Handles

func (s *Service) Handles(language string) bool

Handles reports whether the given fence language is recognized and enabled.

Jump to

Keyboard shortcuts

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