html-pipeline

HTML processing filters and utilities html-pipeline go
0.1.0 released

HTML Pipeline for Go

This is go version of html-pipeline

Other versions

Usage

package main

import (
	"fmt"

	"github.com/PuerkitoBio/goquery"
	"github.com/huacnlee/html-pipeline"
)

// ImageMaxWidthFilter a custom filter example
type ImageMaxWidthFilter struct{}

func (f ImageMaxWidthFilter) Call(doc *goquery.Document) (err error) {
	doc.Find("img").Each(func(i int, node *goquery.Selection) {
		node.SetAttr("style", `max-width: 100%`)
	})

	return
}

func main() {
	pipe := pipeline.NewPipeline([]pipeline.Filter{
		pipeline.MarkdownFilter{},
		pipeline.SanitizationFilter{},
		ImageMaxWidthFilter{},
	})

	markdown := `# Hello world

	<img onclick="javascript:alert" src="https://google.com/foo.jpg"/>`
	out, _ := pipe.Call(html)
	fmt.Println(out)
	// <h1>Hello world</h1>
	// <p><img src="https://google.com/foo.jpg" style="max-width: 100%"/></p>
}

https://play.golang.org/p/RoyEXqx8gui

Built-in filters

License

MIT License

html-pipeline:
  github: huacnlee/html-pipeline
  version: ~> 0.1.0
Crystal none

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently