Documentation ¶
Overview ¶
Package csshtml combines CSS instructions and HTML text to a DOM with style attributes at the selected nodes.
This package can be used to construct a DOM tree from a set of CSS files or strings and applied to HTML files or texts.
Index ¶
- Variables
- func GetAttributes(attrs []html.Attribute) map[string]string
- func ResolveAttributes(attrs []html.Attribute) (resolved map[string]string, newAttributes []html.Attribute)
- type CSS
- func (c *CSS) AddCSSText(fragment string) error
- func (c *CSS) ApplyCSS(doc *goquery.Document) (*goquery.Document, error)
- func (c *CSS) PopDir()
- func (c *CSS) ProcessHTMLChunk(htmltext string) (*goquery.Document, error)
- func (c *CSS) ProcessHTMLFile(filename string) (*goquery.Document, error)
- func (c *CSS) PushDir(dir string)
- type FontFace
- type FontSource
- type Page
Constants ¶
This section is empty.
Variables ¶
var CSSdefaults = `` /* 2070-byte string literal not displayed */
CSSdefaults contains browser-like styling of some elements.
Functions ¶
func GetAttributes ¶
GetAttributes returns a map from all HTML attributes.
func ResolveAttributes ¶
func ResolveAttributes(attrs []html.Attribute) (resolved map[string]string, newAttributes []html.Attribute)
ResolveAttributes returns the resolved styles and the attributes of the node. The argument attrs is unchanged. This function transforms rules such as "margin: 1cm;" into "margin-left: 1cm; margin-right: 1cm; ...". Attributes without a ! prefix are not resolved, just copied to the newAttributes return value. All other attributes are copied to the newAttributes prefixed with a * and all the resolved attributes prefixed with an exclamation mark. The resolved map contains only the resolved attributes and values without a prefix.
Types ¶
type CSS ¶
type CSS struct { Pages map[string]Page FileFinder func(string) (string, error) FontFaces []FontFace // contains filtered or unexported fields }
CSS is the main structure that contains cascading style sheet information. Multiple stylesheets can be added to the CSS structure and then applied to HTML.
func NewCSSParserWithDefaults ¶
func NewCSSParserWithDefaults() *CSS
NewCSSParserWithDefaults returns a new CSS object with the default stylesheet included. This is a convenience function which adds the CSSdefaults to the returned CSS struct.
func (*CSS) AddCSSText ¶
AddCSSText parses CSS text and appends the rules to the previously read rules. If the fragment contains relative links to other files (fonts or other stylesheets for example), the dir stack must be set in advance.
func (*CSS) ApplyCSS ¶
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) ProcessHTMLChunk ¶
ProcessHTMLChunk reads the HTML text. If there are linked style sheets (<link href=...) these are also read. After reading, the CSS is applied to the HTML DOM which is returned.
func (*CSS) ProcessHTMLFile ¶
ProcessHTMLFile opens an HTML file, reads linked stylesheets, applies the CSS rules and returns the DOM structure.
type FontFace ¶
type FontFace struct { Weight int Style string Family string Source []FontSource Features []string SizeAdjust float64 }
FontFace contains information from a @font-face rule.
type FontSource ¶
FontSource has information from the src attribute.