srcset

package module
v0.0.0-...-06e7f27 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 2 Imported by: 11

README

go srcset parser

srcset provides a parser for the HTML5 srcset attribute, based on the WHATWG reference algorithm.

Loosely ported from https://github.com/albell/parse-srcset.

Documentation

Overview

Package srcset `srcset` provides a parser for the HTML5 `srcset` attribute, based on the [WHATWG reference algorithm](https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute). TODO: This works, but I dislike the state manipulation. Use more go-like structures for reading and tokenization, like bufio.Scanner

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImageSource

type ImageSource struct {
	URL     string
	Width   *int64
	Height  *int64
	Density *float64
	Offset  int
}

ImageSource is a structure that contains an image definition.

type SourceSet

type SourceSet []ImageSource

SourceSet is the result of parsing the value of a srcset attribute. A SourceSet consists of multiple ImageSource instances.

func Parse

func Parse(input string) SourceSet

Parse takes the value of a srcset attribute and parses it.

Jump to

Keyboard shortcuts

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