html

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: BSD-3-Clause Imports: 29 Imported by: 1

README

logo

Go Reference

LiberaPay receives patrons

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	URL2Reader(url string) (io.ReadCloser, error)
}

Config configures HTML rendering.

type ConfigLogger

type ConfigLogger interface {
	Log(format string, args ...any)
}

ConfigLogger may be optionally implemented by a Config instance. It provides a mechanism to report back errors etc.

type ConfigNavigator

type ConfigNavigator interface {
	Navigate(url string) error
}

ConfigNavigator may be optionally implemented by a Config instance. It provides a mechanism to handle link clicks.

type ConfigQuirks

type ConfigQuirks interface {
	QuirksMode(suggested bool) (enforced bool)
}

ConfigQuirks may be optionally implemented by a Config instance. It provides a mechanism to enforce quirks mode or non-quirks mode. Returning other than the suggested mode may have unpredictable results.

type ConfigUserAgentStyleSheet

type ConfigUserAgentStyleSheet interface {
	UserAgentStyleSheet(quirksMode bool) string
}

ConfigUserAgentStyleSheet may be optionally implemented by a Config instance. It provides a mechanism to use other than the default user agent style sheet. Setting a non-standard user agent style sheet may have unpredictable results.

type DisplayList

type DisplayList struct {
	ID int
	// contains filtered or unexported fields
}

DisplayList collects items to display in a HTML widget. The ID field reflects the value returned from [SetWindowLocation].

func (*DisplayList) Draw

func (dl *DisplayList) Draw(budget time.Duration) (completed bool)

Draw draws 'l' until complete or until 'budget' is exhausted.

This function allows to incrementally update a HTML widget while keeping the GUI responsive.

As any other GUI updates, this method can be executed only on the GUI thread. Example code running draw on the GUI thread:

v := html.NewPreview(nil, cfg)
ch := make(chan *html.DisplayList, 20)
var dl *html.DisplayList

tk.NewTicker(100*time.Millisecond, func() {
	if dl == nil {
	out:
		for {
			select {
			case dl = <-ch:
				// Drain.
			default:
				break out
			}
		}
	}
	if dl != nil && dl.Draw(80*time.Millisecond) {
		dl = nil
	}
})

v.SetWindowLocation("index.html", ch)

The above code demonstrates only a basic approach. It does not handle, for instance, the situation when a a particular display list is not yet fully drawn but a newer one becomes available, making drawing the rest of the previous list a waste of time.

type Preview

type Preview struct {
	*TextWidget
	// contains filtered or unexported fields
}

Preview provides a TextWidget based, preview quality rendering of simple HTML documents.

Only a limited subset of HTML/CSS is recognized and only the flow layout is supported, approximately. Everything else is ignored.

The intended use is for presenting small and simple markdown-only documents rendered to HTML by the gomarkdown package. There are no plans at the moment to extend the capabilities of Preview beyond that — the text widget is not compatible with most modern HTML/CSS features.

func NewPreview

func NewPreview(parent *Window, cfg Config, options ...Opt) (r *Preview)

NewPreview returns a new Preview.

func (*Preview) SeeID

func (p *Preview) SeeID(id string) bool

SeeID attempts to make HTML node 'id' visible and returns true if the node was found.

func (*Preview) SetWindowLocation

func (p *Preview) SetWindowLocation(href string, listChan chan *DisplayList, seeTop bool) (id int, err error)

SetWindowLocation computes the display list for 'href'. It does so in a separate non-GUI goroutine. If the 'listChan' is non-nil, the result will be sent to the channel.

If the channel is nil, SetWindowLocation becomes blocking and does not return until the display list is fully shown in the widget.

It is recommended to pass a non-nil 'listChan' to keep the GUI interactive.

Jump to

Keyboard shortcuts

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