htmldoc

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package htmldoc : Provides local document interface for htmltest. Models a store of documents, individual documents and their internal and external references.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttrPresent

func AttrPresent(attrs []html.Attribute, key string) bool

AttrPresent : Is key present within attrs?

func ExtractAttrs

func ExtractAttrs(attrs []html.Attribute, keys []string) map[string]string

ExtractAttrs : From attrs extract the asked for keys

func GetAttr

func GetAttr(attrs []html.Attribute, key string) string

GetAttr : From attrs extract single attr

func GetID

func GetID(attrs []html.Attribute) string

GetID : Get hash/fragment id from node.Attrs

func URLStripQueryString

func URLStripQueryString(urlStr string) string

URLStripQueryString : Utility function to remove query string from given urlStr.

Types

type Document

type Document struct {
	FilePath   string // Relative to the shell session
	SitePath   string // Relative to the site root
	BasePath   string // Base for relative links
	IgnoreTest bool   // Ignore this Document for testing.

	NodesOfInterest []*html.Node  // Slice of nodes to run checks on
	State           DocumentState // Link to a DocumentState struct
	DoctypeNode     *html.Node    // Pointer to doctype node if exists
	// contains filtered or unexported fields
}

Document struct, representation of a document within the tested site

func (*Document) Init

func (doc *Document) Init()

Init : Initialise the Document struct doesn't mesh nice with the NewXYZ() convention but many optional parameters for Document and no parameter overloading in Go

func (*Document) IsHashValid

func (doc *Document) IsHashValid(hash string) bool

IsHashValid : Is a hash/fragment present in this Document.

func (*Document) Parse

func (doc *Document) Parse()

Parse : Ask Document to parse its HTML file. Returns quickly if this has already been done. Thread safe. Either called when the document is tested or when another document needs data from this one.

type DocumentState

type DocumentState struct {
	FaviconPresent bool // Have we found a favicon in the document?
}

DocumentState struct, used by checks that depend on the document being parsed.

type DocumentStore

type DocumentStore struct {
	BasePath           string               // Path, relative to cwd, the site is located in
	IgnorePatterns     []interface{}        // Regexes of directories to ignore
	Documents          []*Document          // All of the documents, used to iterate over
	DocumentPathMap    map[string]*Document // Maps slash separated paths to documents
	DocumentExtension  string               // File extension to look for
	DirectoryIndex     string               // What file is the index of the directory
	IgnoreTagAttribute string               // Attribute to ignore element and children if found on element
}

DocumentStore struct, store of Documents including Document discovery

func NewDocumentStore

func NewDocumentStore() DocumentStore

NewDocumentStore : Create and return a new Document store.

func (*DocumentStore) AddDocument

func (dS *DocumentStore) AddDocument(doc *Document)

AddDocument : Add a document to the document store.

func (*DocumentStore) Discover

func (dS *DocumentStore) Discover()

Discover : Discover all documents within DocumentStore.BasePath.

func (*DocumentStore) ResolvePath

func (dS *DocumentStore) ResolvePath(refPath string) (*Document, bool)

ResolvePath : Resolves internal absolute paths to documents.

func (*DocumentStore) ResolveRef

func (dS *DocumentStore) ResolveRef(ref *Reference) (*Document, bool)

ResolveRef : Proxy to ResolvePath via ref.RefSitePath()

type Reference

type Reference struct {
	Document *Document  // Document node is in
	Node     *html.Node // Node reference was created from
	Path     string     // href/src taken verbatim from source
	URL      *url.URL   // URL object created from Path
}

Reference struct, representation of the link between a document and a resource.

func NewReference

func NewReference(document *Document, node *html.Node, path string) (*Reference, error)

NewReference : Create a new reference given a document, node and path. Generates the URL object.

func (*Reference) IsInternalAbsolute

func (ref *Reference) IsInternalAbsolute() bool

IsInternalAbsolute : Is an internal absolute link.

func (*Reference) RefSitePath

func (ref *Reference) RefSitePath() string

RefSitePath : For internals, return a path to the referenced file relative to the 'site root'.

func (*Reference) Scheme

func (ref *Reference) Scheme() string

Scheme : Returns the scheme of the reference. Uses URL.Scheme and adds "file" and "self" schemes for inter-file and intra-file references.

func (*Reference) URLString

func (ref *Reference) URLString() string

URLString : Proxy for URL.String but deals with other valid URL types, such as missing protocol URLs.

Jump to

Keyboard shortcuts

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