markdown

package
v0.9.71 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ISSUE_NAME_STYLE_NUMERIC      = "numeric"
	ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric"
)

Variables

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

	// CommitPattern matches link to certain commit with or without trailing hash,
	// e.g. https://try.gogs.io/gogs/gogs/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2
	CommitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`)

	// IssueFullPattern matches link to an issue with or without trailing hash,
	// e.g. https://try.gogs.io/gogs/gogs/issues/4#issue-685
	IssueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`)
	// IssueNumericPattern matches string that references to a numeric issue, e.g. #1287
	IssueNumericPattern = regexp.MustCompile(`( |^|\()#[0-9]+\b`)
	// IssueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
	IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`)

	// Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae
	Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`)
)
View Source
var Sanitizer = bluemonday.UGCPolicy()

Functions

func BuildSanitizer

func BuildSanitizer()

BuildSanitizer initializes sanitizer with allowed attributes based on settings. This function should only be called once during entire application lifecycle.

func FindAllMentions added in v0.9.46

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 PostProcess

func PostProcess(rawHtml []byte, urlPrefix string, metas map[string]string) []byte

PostProcess treats different types of HTML differently, and only renders special links for plain text blocks.

func Render

func Render(rawBytes []byte, urlPrefix string, metas map[string]string) []byte

Render renders Markdown to HTML with special links.

func RenderIssueIndexPattern

func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte

RenderIssueIndexPattern renders issue indexes to corresponding links.

func RenderRaw

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

RenderRaw renders Markdown to HTML without handling 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, metas map[string]string) []byte

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

func RenderString

func RenderString(raw, urlPrefix string, metas map[string]string) string

RenderString renders Markdown to HTML with special links and returns string type.

Types

type Renderer

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

Renderer is a extended version of underlying render object.

func (r *Renderer) 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 (*Renderer) Image

func (r *Renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte)

Image defines how images should be processed to produce corresponding HTML elements.

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

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

func (*Renderer) ListItem

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

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

Jump to

Keyboard shortcuts

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