Popularity
5.1
Growing
Activity
0.0
Stable
21
3
3
Programming language: Go
License: MIT License
Tags:
Markdown/Text Processors
Latest version: v0.3.0
html-pipeline alternatives and similar shards
Based on the "Markdown/Text Processors" category.
Alternatively, view html-pipeline alternatives based on common mentions on social networks and blogs.
Do you think we are missing an alternative of html-pipeline or a related project?
Popular Comparisons
README
HTML Pipeline for Go
This is go version of html-pipeline
Other versions
- html-pipeline - Ruby
- html-pipeline.cr - Crystal
Usage
package main
import (
"fmt"
"github.com/PuerkitoBio/goquery"
pipeline "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{},
pipeline.MentionFilter{
Prefix: "#",
Format: func(name string) string {
return fmt.Sprintf(`<a href="https://github.com/topic/%s">#%s</a>`, name, name)
},
},
pipeline.MentionFilter{
Prefix: "@",
Format: func(name string) string {
return fmt.Sprintf(`<a href="https://github.com/%s">@%s</a>`, name, name)
},
},
})
markdown := `# Hello world
 [Click me](javascript:alert)
This is #html-pipeline example, @huacnlee created.`
out, _ := pipe.Call(markdown)
fmt.Println(out)
/*
<h1>Hello world</h1>
<p><img alt="" style="max-width: 100%"/> Click me</p>
<p>This is <a href="https://github.com/topic/html-pipeline">#html-pipeline</a> example, <a href="https://github.com/huacnlee">@huacnlee</a> created.</p>
*/
}
https://play.golang.org/p/zB0T7KczdB4
Built-in filters
- SanitizationFilter - Use [bluemonday](github.com/microcosm-cc/bluemonday) default UGCPolicy to sanitize html
- MarkdownFilter - Use blackfriday to covert Markdown to HTML.
- MentionFilter - Match Mention or HashTag like Twitter.
- HTMLEscapeFilter - HTML Escape for plain text.
- SimpleFormatFilter - Format plain text for covert
\n\n
into paragraph, like Rails simple_format. - AutoCorrectFilter - Use go-auto-correct to automatically add spaces between Chinese and English words.
License
MIT License
*Note that all licence references and agreements mentioned in the html-pipeline README section above
are relevant to that project's source code only.