Popularity
5.0
Declining
Activity
0.0
Stable
20
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?

Add another 'Markdown/Text Processors' Shard

README

HTML Pipeline for Go

This is go version of html-pipeline

Other versions

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

![](javascript:alert) [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

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.