server

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package server provides the HTTP preview server for mdp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	File          string
	Port          int
	OpenBrowser   bool
	Theme         string        // built-in theme name, file path, or "auto".
	HljsTheme     string        // vendored hljs sheet for custom theme files (github, github-dark).
	ScrollSync    bool          // Enable scroll sync via /cursor endpoint.
	CustomCSS     string        // Path to custom CSS file to inject after default styles.
	OpenToNetwork bool          // Listen on 0.0.0.0 instead of localhost.
	IdleTimeout   time.Duration // Shut down when no clients connected for this long (0 = disabled).
}

Config holds the server configuration.

type Server

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

Server is the HTTP preview server.

func New

func New(cfg Config) (*Server, error)

New creates a new Server from the given config. The listen address is resolved eagerly so callers can read it via Addr() before calling ListenAndServe.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the resolved listen address (host:port).

func (*Server) Broadcast

func (s *Server) Broadcast(md []byte) error

Broadcast parses the given markdown and sends the rendered HTML to all connected WebSocket and SSE clients.

func (*Server) BroadcastFile

func (s *Server) BroadcastFile() error

BroadcastFile reads the configured file and broadcasts its rendered content.

func (*Server) Close

func (s *Server) Close()

Close shuts down the server, closing all WebSocket and SSE connections.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the HTTP server and blocks until it exits. Returns nil on clean shutdown (e.g. idle timeout or Close()).

func (*Server) ReadStdin

func (s *Server) ReadStdin(r io.Reader)

ReadStdin reads newline-delimited JSON messages from r and dispatches them. It blocks until r is closed or an unrecoverable error occurs.

func (*Server) SendCursor

func (s *Server) SendCursor(line int) error

SendCursor broadcasts a cursor position update to all connected clients.

Jump to

Keyboard shortcuts

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