htmlutil

package
v0.0.0-...-2c87074 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Unlicense Imports: 6 Imported by: 0

Documentation

Overview

Package htmlutil implements some html utility functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFile

func ParseFile(htmlPath string) (n *html.Node, err error)

ParseFile parses the provided HTML file and returns an HTML node.

func Render

func Render(w io.Writer, n *html.Node)

Render renders a simplified version of the provided HTML node. It will strip doctype nodes, trim spaces on text nodes and insert indentation.

Note: Render doesn't guarantee that the semantics of the page are preserved.

Example
package main

import (
	"log"
	"os"

	"github.com/mewkiz/pkg/htmlutil"
)

func main() {
	n, err := htmlutil.ParseFile("testdata/0001.html")
	if err != nil {
		log.Fatalln(err)
	}
	htmlutil.Render(os.Stdout, n)
}
Output:

<html>
   <head>
      <meta charset="utf-8">
      <title>
         0001
      </title>
   </head>
   <body>
      <img src="test.png" alt="test">
      <p>
         Test page.
      </p>
   </body>
</html>

func RenderClean

func RenderClean(node *html.Node) (htmlStr string, err error)

RenderClean renders the provided HTML node and returns it as a string. It is a convenience function for html.Render.

func RenderToString

func RenderToString(n *html.Node) string

RenderToString renders a simplified version of the provided HTML node and returns it as a string. It will strip doctype nodes, trim spaces on text nodes and insert indentation.

Note: RenderToString doesn't guarantee that the semantics of the page are preserved.

Types

This section is empty.

Jump to

Keyboard shortcuts

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