hcj

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

hcj

HCJ is an HTML/CSS and JS renderer.

Status

As of January 2023, HCJ has semi-functional HTML and CSS, and no JS capabilities.

Goal Status
HTML Parsing Complete via golang.org/x/net/html
CSS Parsing ~95% complete
JS Parsing 0% complete
HTML/CSS Rendering ~10% complete
JS Rendering 0% complete
Tests Passing 42
Test Count 228

Philosophy

This project is test driven, it will be considered complete when there are no test files run through its test suites that fail to render a correct image or video output, and when these suites fully cover the feature set of the target languages.

The input data for test suites can be found in testdata.

Contributing

  • Choose an existing test file from a todo directory or find your own. The former is more likely to be accepted as a non-duplicate test. Move this to a in testdata directory.
  • Change the library such that the test suites produce a valid render of the selected test file.
  • Ensure these changes do not change, or do not significantly change, or only correct existing mistakes in existing output files.
  • Open a PR with the code and testdata changes.

Notes

  • HTML and CSS rendering are combined as HTML cannot be rendered without some concept of styles; style-less HTML is still driven by baked-in default styles, which are roughly agreed upon by existing web browsers.
  • This project targets CSS4 and HTML5, but earlier versions of these languages should be targeted for intermediate functionality goals.
  • Some functionality may be explicitly avoided to produce a library with less potential exploits, particularly around code execution, network access, and local file system access.
  • To date this project is not interested in looking at existing open source implementations e.g. Chromium and copying their approach; this would save time at the cost of producing two identical implementations, with this project being likely inferior.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSelector = fmt.Errorf("invalid selector")

Functions

func RenderHTML

func RenderHTML(htmlReader io.Reader, dims intgeom.Point2) (*render.Sprite, error)

Types

type AttributeSelector

type AttributeSelector interface {
	Match(pn *ParsedNode) bool
}

func ParseAttributeSelector

func ParseAttributeSelector(selector string) (AttributeSelector, error)

type CSS

type CSS struct {
	Selectors map[string]map[string]string
}

func DefaultCSS

func DefaultCSS() CSS

func ParseCSS

func ParseCSS(s string) CSS

func (CSS) Merge

func (c CSS) Merge(c2 CSS) CSS

Merge combines two CSS maps, preferring settings in c2 over c. c is modified as a result.

type ParseNodeOption

type ParseNodeOption func(ParseNodeOptions) ParseNodeOptions

func WithCSS

func WithCSS(v CSS) ParseNodeOption

func WithParentStyle

func WithParentStyle(v map[string]string) ParseNodeOption

type ParseNodeOptions

type ParseNodeOptions struct {
	CSS         CSS
	ParentStyle map[string]string
}

type ParsedNode

type ParsedNode struct {
	Raw              *html.Node
	Tag              string
	ID               string
	Classes          []string
	Style            map[string]string
	PseudoClassStyle map[PseudoClass]map[string]string
	// PseudoClassSupers are PseudoClasses with parameters like lang(in)
	// they are not supported yet
	PseudoClassSuperStyle map[string]map[string]string
	FirstChild            *ParsedNode
	// LastChild
	NextSibling *ParsedNode
}

func ParseNode

func ParseNode(node *html.Node, opts ...ParseNodeOption) *ParsedNode

func (*ParsedNode) CalculateStyle

func (pn *ParsedNode) CalculateStyle(css CSS)

type PseudoClass

type PseudoClass uint8
const (
	PseudoClassActive      PseudoClass = iota
	PseudoClassChecked     PseudoClass = iota
	PseudoClassDisabled    PseudoClass = iota
	PseudoClassEmpty       PseudoClass = iota
	PseudoClassEnabled     PseudoClass = iota
	PseudoClassFirstChild  PseudoClass = iota
	PseudoClassFirstOfType PseudoClass = iota
	PseudoClassFocus       PseudoClass = iota
	PseudoClassHover       PseudoClass = iota
	PseudoClassInRange     PseudoClass = iota
	PseudoClassInvalid     PseudoClass = iota
	PseudoClassLastChild   PseudoClass = iota
	PseudoClassLastOfType  PseudoClass = iota
	PseudoClassLink        PseudoClass = iota
	PseudoClassOnlyOfType  PseudoClass = iota
	PseudoClassOnlyChild   PseudoClass = iota
	PseudoClassOptional    PseudoClass = iota
	PseudoClassOutOfRange  PseudoClass = iota
	PseudoClassReadOnly    PseudoClass = iota
	PseudoClassReadWrite   PseudoClass = iota
	PseudoClassRequired    PseudoClass = iota
	PseudoClassRoot        PseudoClass = iota
	PseudoClassTarget      PseudoClass = iota
	PseudoClassValid       PseudoClass = iota
	PseudoClassVisited     PseudoClass = iota
)

PseudoClasses

type Selector

type Selector struct {
	Tag       string
	ID        string // Multiple IDs are supported, but we lack an example where they would be used. Styles with multiple IDs should be discarded for now.
	Attribute string
	Classes   []string
	Global    bool
}

func ParseSelector

func ParseSelector(s string) (Selector, error)

Jump to

Keyboard shortcuts

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