Skip to content

mpfund/htmlcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

htmlcheck

simple, fast and easy html checker in Go

package main

import (
	"fmt"
	"github.com/BlackEspresso/htmlcheck"
)

func main() {
	validater := htmlcheck.Validator{}

	validLink := htmlcheck.ValidTag{
		Name:          "a",
		Attrs:         []string{"href", "target", "id"},
		IsSelfClosing: false,
	}

	validater.AddValidTag(validLink)
	// first check
	errors := validater.ValidateHtmlString("<a href='http://google.com'>m</a>")
	if len(errors) == 0 {
		fmt.Println("ok")
	} else {
		fmt.Println(errors)
	}

	// second check
	// notice the missing / in the second <a>:
	errors = validater.ValidateHtmlString("<a href='http://google.com'>m<a>")
	if len(errors) == 0 {
		fmt.Println("ok")
	} else {
		fmt.Println(errors)
	}
}

prints

ok
tag 'a' is not properly closed

About

simple, fast and easy html checker in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages