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 ¶
const ( LangVuego = "vuego" LangPHP = "php" LangExec = "exec" LangSQL = "sql" )
Canonical language identifiers.
const EvalPath = "/api/codeblock/eval"
EvalPath is the HTTP path that the frontend posts evaluation requests to.
const ScriptPath = "/assets/codeblock.js"
ScriptPath is the URL the runnable widget loads its behaviour from.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
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 ¶
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 ¶
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 ¶
func (s *Service) Eval(ctx context.Context, req model.EvalRequest) model.EvalResponse
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.