csshtml

package
v0.0.0-...-3435f2a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: BSD-3-Clause Imports: 16 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CSSdefaults = `` /* 2021-byte string literal not displayed */

CSSdefaults contains browser-like styling of some elements.

Functions

func PapersizeWidthHeight

func PapersizeWidthHeight(spec string) (string, string)

PapersizeWidthHeight converts the spec to the width and height. The parameter can be a known paper size (such as A4 or letter) or a one or two parameter string such as 20cm 20cm.

func ResolveAttributes

func ResolveAttributes(attrs []html.Attribute) (resolved map[string]string, attributes map[string]string, newAttributes []html.Attribute)

ResolveAttributes returns the resolved styles and the attributes of the node. It changes "margin: 1cm;" into "margin-left: 1cm; margin-right: 1cm; ...".

Types

type CSS

type CSS struct {
	FrontendDocument *frontend.Document
	Stylesheet       []sBlock
	Pages            map[string]Page
	FileFinder       func(string) (string, error)
	// contains filtered or unexported fields
}

CSS wraps multiple stylesheets.

func NewCSSParser

func NewCSSParser() *CSS

NewCSSParser returns a new CSS object

func NewCSSParserWithDefaults

func NewCSSParserWithDefaults() *CSS

NewCSSParserWithDefaults returns a new CSS object with the default stylesheet included.

func (*CSS) AddCSSText

func (c *CSS) AddCSSText(fragment string) error

AddCSSText parses CSS text and appends the rules to the previously read rules.

func (*CSS) ApplyCSS

func (c *CSS) ApplyCSS(doc *goquery.Document) (*goquery.Document, error)

ApplyCSS resolves CSS rules in the DOM. Each CSS rule is added to the selection as an attribute (prefixed with a !). Pseudo elements are prefixed with ::.

func (*CSS) FindFile

func (c *CSS) FindFile(filename string) (string, error)

FindFile returns the absolute path of the file. If the requested file is found with the FileFinder then this value is returned instead.

func (*CSS) ParseHTMLFragment

func (c *CSS) ParseHTMLFragment(htmltext string) (*goquery.Document, error)

ParseHTMLFragment takes the HTML text and the CSS text and returns goquery selection.

func (*CSS) ParseHTMLFragmentWithCSS

func (c *CSS) ParseHTMLFragmentWithCSS(htmltext, csstext string) (*goquery.Document, error)

ParseHTMLFragmentWithCSS takes the HTML text and the CSS text and returns goquery selection.

func (*CSS) PopDir

func (c *CSS) PopDir()

PopDir removes the last entry from the dir stack.

func (*CSS) PushDir

func (c *CSS) PushDir(dir string)

PushDir adds a directory to the dir stack. When a file is opened, all new Open calls are relative to this directory.

func (*CSS) ReadHTMLChunk

func (c *CSS) ReadHTMLChunk(htmltext string) (*goquery.Document, error)

ReadHTMLChunk reads the HTML text. If there are linked style sheets (<link href=...) these are also read. After reading the HTML and CSS the HTML is stored in c.document.

func (*CSS) ReadHTMLWithStyles

func (c *CSS) ReadHTMLWithStyles(filename string) (*goquery.Document, error)

ReadHTMLWithStyles opens an HTML file and read linked stylesheets.

func (*CSS) Show

func (c *CSS) Show() string

Show returns the CSS written as a nice string

type Page

type Page struct {
	PageArea     map[string]map[string]string // key value pairs for the page areas
	Attributes   []html.Attribute
	Papersize    string
	MarginLeft   string
	MarginRight  string
	MarginTop    string
	MarginBottom string
	// contains filtered or unexported fields
}

Page defines a page.

Jump to

Keyboard shortcuts

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