document

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package document implements Markdown document processing and serving.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultMarkdown is the default converter for Markdown to HTML.
	DefaultMarkdown = goldmark.New(
		goldmark.WithExtensions(extension.GFM),
		goldmark.WithParserOptions(parser.WithAutoHeadingID()),
	)
)

Functions

This section is empty.

Types

type Document

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

Document is a HTML representation of Markdown text.

func NewDocument added in v0.4.0

func NewDocument(name string, md goldmark.Markdown) *Document

NewDocument creates a new document with the given name and Markdown converter.

func (*Document) Borrow

func (d *Document) Borrow(fn func(buf []byte) error) error

Borrow temporarily borrows the document's HTML for the lifetime of fn. buf must not be mutated or used outside of fn.

func (*Document) Convert

func (d *Document) Convert(buf []byte) error

Convert converts the Markdown text in buf into the document as HTML.

func (*Document) Name added in v0.4.0

func (d *Document) Name() string

Name returns the document's name.

func (*Document) ReadFrom added in v0.4.0

func (d *Document) ReadFrom(r io.Reader) (n int64, err error)

ReaderFrom reads Markdown text from the reader and converts it into the document as HTML.

func (*Document) WriteTo added in v0.4.0

func (d *Document) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the document's HTML to the writer.

type Library

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

Library is a collection of Markdown documents.

func NewLibrary

func NewLibrary(src source.Source, md goldmark.Markdown) *Library

NewLibrary creates a new library using the given source and Markdown converter. If md is nil, DefaultMarkdown is used.

func (*Library) Create added in v0.4.0

func (l *Library) Create(name string) (*Document, error)

Create reads a document from the library's source. If the document exists, the existing document's content is reloaded.

func (*Library) Open added in v0.4.0

func (l *Library) Open(name string) (d *Document, ok bool)

Open reads the document with name. If the document does not exist, ok is false.

func (*Library) Remove added in v0.4.0

func (l *Library) Remove(name string) (ok bool)

Remove deletes a document from the library. If the document does not exist, ok is false.

func (*Library) Watcher added in v0.4.0

func (l *Library) Watcher() (w source.Watcher, ok bool)

Watcher returns the library's source as a Watcher. If the source does not support file watching, ok is false.

type Server added in v0.4.0

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

Server serves documents and their accompanying CSS/JS assets over HTTP.

func NewServer added in v0.4.0

func NewServer(url *url.URL, md goldmark.Markdown) (*Server, error)

NewServer creates a new server with a source URL.

func (*Server) Close added in v0.4.0

func (s *Server) Close()

Close closes the server.

func (*Server) ServeHTTP added in v0.4.0

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*Server) SetLogger added in v0.4.0

func (s *Server) SetLogger(log *log.Logger)

SetLogger sets the server's logger. By default, the global default logger from log.Default() is used.

type Template added in v0.4.0

type Template struct {
	// The HTML title to use.
	Title string

	// The directory where assets are served.
	// index.js and index.css must be present in the directory.
	AssetURL string

	// The path where SSE events are served.
	EventURL string

	// The initial content of the HTML page.
	Content template.HTML
}

Template is the HTML template for serving a document. For the template itself, see template.html.

func (*Template) Execute added in v0.4.0

func (t *Template) Execute(w io.Writer) error

Jump to

Keyboard shortcuts

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