html

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 8 Imported by: 2

Documentation

Overview

Package html helper library for parsing HTML for Altid markup

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cleaner

type Cleaner struct {
	// contains filtered or unexported fields
}

Cleaner wraps the underlying WriteCloser, and handles parsing HTML into Altid-flavoured markdown, to the underlying writer.

func NewCleaner

func NewCleaner(w io.WriteCloser, p Handler) (*Cleaner, error)

NewCleaner returns a usable Cleaner struct if either w or p are nil it will return an error

func (*Cleaner) Close

func (c *Cleaner) Close()

Close calls the underlying WriteCloser's Close method.

func (*Cleaner) Parse

func (c *Cleaner) Parse(r io.ReadCloser) error

Parse - This assumes properly formatted html, and will return an error from the underlying html tokenizer if encountered Parse writes properly formatted Altid markup to the underlying writer, translating many elements into their markdown form. This will be considered lossy, as the token metadata is ignored in all cases. This will return any errors encountered, and EOF on success

func (*Cleaner) Write

func (c *Cleaner) Write(msg []byte) (n int, err error)

Write calls the underlying WriteCloser's Write method. It does not modify the contents of `msg`

func (*Cleaner) WriteString

func (c *Cleaner) WriteString(msg string) (n int, err error)

WriteString is the same as Write, except it accepts a string instead of bytes.

type Handler

type Handler interface {
	NavHandler
	ImgHandler
}

Handler will be called to satisfy both <nav> and <img> elements

type Image

type Image struct {
	Src []byte
	Alt []byte
}

Image is an image tag <img src="foo" alt="bar">

func (*Image) String

func (i *Image) String() string

type ImgHandler

type ImgHandler interface {
	Img(*Image) error
}

ImgHandler is called when the parser encounters an <img> element

type NavHandler interface {
	Nav(*URL) error
}

NavHandler is called when the parser encounters a <nav> element

type URL

type URL struct {
	Href []byte
	Msg  []byte
}

URL is a url tag <a href="something">Msg</a>

func (*URL) String

func (u *URL) String() string

Jump to

Keyboard shortcuts

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