svgcontent

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package svgcontent extracts the *semantic* (visible / structural) content of a rendered metrics SVG so tests can assert on what a viewer actually sees — not on byte equality or pixel height.

It exists to close the verification gap behind issues #463–#472: the byte-golden and height/file-size suites are circular (the goldens were generated from the same implementation under test) or too coarse to notice "License is missing", "files changed is absent", or "the card rendered empty". This package parses the SVG (including the xhtml inside <foreignObject>) with goquery, strips non-rendered nodes (<style>/<defs>/<script>), and exposes the remaining visible text and DOM structure for content-level assertions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(raw []byte, sub string) (bool, error)

Contains reports whether the visible text contains sub, comparing case-insensitively after whitespace normalization. Returns an error only if the SVG fails to parse.

func Doc

func Doc(raw []byte) (*goquery.Document, error)

Doc parses raw SVG/HTML bytes into a goquery document with the non-rendered nodes (<style>, <defs>, <script>) removed, so every subsequent query and Text() call sees only content a viewer would actually render.

func MatchCount

func MatchCount(raw []byte, re *regexp.Regexp) (int, error)

MatchCount returns how many times re matches across the visible text (not the raw markup). Use for "does a '<n> files changed' label appear" style structural assertions.

func Normalize

func Normalize(s string) string

Normalize trims and collapses internal whitespace to single spaces. Exported so callers can normalize an expected marker the same way before a Contains check.

func SelectorCount

func SelectorCount(raw []byte, selector string) (int, error)

SelectorCount returns how many nodes match the goquery selector (after style/defs/script removal). Use for "the card body is not empty" structural assertions where text alone is insufficient.

func Tokens

func Tokens(raw []byte) ([]string, error)

Tokens returns the sorted, de-duplicated, lowercased whitespace tokens of the visible text. Useful for set-subset comparisons between an upstream reference and our output.

func VisibleText

func VisibleText(raw []byte) (string, error)

VisibleText returns the document's rendered text content collapsed to single spaces. Style/defs/script have already been stripped by Doc, so CSS rules and `<defs>` payloads do not leak in.

Types

This section is empty.

Jump to

Keyboard shortcuts

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