markup

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MentionPattern matches string that mentions someone, e.g. @Unknwon
	MentionPattern = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`)

	// Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae
	// FIXME: this pattern matches pure numbers as well, right now we do a hack to check in RenderSha1CurrentPattern
	// by converting string to a number.
	Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`)
)

Functions

func FindAllMentions

func FindAllMentions(content string) []string

FindAllMentions matches mention patterns in given content and returns a list of found user names without @ prefix.

func IsMarkdownFile

func IsMarkdownFile(name string) bool

IsMarkdownFile reports whether name looks like a Markdown file based on its extension.

func IsReadmeFile

func IsReadmeFile(name string) bool

IsReadmeFile reports whether name looks like a README file based on its extension.

func Markdown

func Markdown(input interface{}, urlPrefix string) []byte

Markdown takes a string or []byte and renders to HTML in Markdown syntax with special links.

func NewSanitizer

func NewSanitizer()

NewSanitizer initializes sanitizer with allowed attributes based on settings. Multiple calls to this function will only create one instance of Sanitizer during entire application lifecycle.

func RawMarkdown

func RawMarkdown(body []byte, urlPrefix string) []byte

RawMarkdown renders Markdown to HTML without handling special links.

func Render

func Render(typ Type, input interface{}, urlPrefix string) []byte

Render takes a string or []byte and renders to HTML in given type of syntax with special links.

func RenderSha1CurrentPattern

func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte

RenderSha1CurrentPattern renders SHA1 strings to corresponding links that assumes in the same repository.

func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte

RenderSpecialLink renders mentions, indexes and SHA1 strings to corresponding links.

func Sanitize

func Sanitize(s string) string

Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.

func SanitizeBytes

func SanitizeBytes(b []byte) []byte

SanitizeBytes takes a []byte slice that contains a HTML fragment or document and applies policy whitelist.

Types

type MarkdownRenderer

type MarkdownRenderer struct {
	blackfriday.Renderer
	// contains filtered or unexported fields
}

MarkdownRenderer is a extended version of underlying Markdown render object.

func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int)

AutoLink defines how auto-detected links should be processed to produce corresponding HTML elements. Reference for kind: https://github.com/russross/blackfriday/blob/master/markdown.go#L69-L76

func (r *MarkdownRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte)

Link defines how formal links should be processed to produce corresponding HTML elements.

func (*MarkdownRenderer) ListItem

func (r *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags int)

ListItem defines how list items should be processed to produce corresponding HTML elements.

type Sanitizer

type Sanitizer struct {
	// contains filtered or unexported fields
}

Sanitizer is a protection wrapper of *bluemonday.Policy which does not allow any modification to the underlying policies once it's been created.

type Type

type Type string

Type of special text

Jump to

Keyboard shortcuts

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