markdown

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IssueNameStyleNumeric      = "numeric"
	IssueNameStyleAlphanumeric = "alphanumeric"
)

Issue name styles

Variables

View Source
var (

	// MentionPattern matches string that mentions someone, e.g. @Unknwon
	MentionPattern = regexp.MustCompile(`(\s|^|\W)@[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`)
	// CrossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository
	// e.g. gogits/gogs#12345
	CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z]+/[0-9a-zA-Z]+#[0-9]+\b`)

	// Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae
	// Although SHA1 hashes are 40 chars long, the regex matches the hash from 7 to 40 chars in length
	// so that abbreviated hash links can be used as well. This matches git and github useability.
	Sha1CurrentPattern = regexp.MustCompile(`(?:^|\s|\()([0-9a-f]{7,40})\b`)

	// ShortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
	ShortLinkPattern = regexp.MustCompile(`(\[\[.*?\]\]\w*)`)

	// AnySHA1Pattern allows to split url containing SHA into parts
	AnySHA1Pattern = regexp.MustCompile(`(http\S*)://(\S+)/(\S+)/(\S+)/(\S+)/([0-9a-f]{40})(?:/?([^#\s]+)?(?:#(\S+))?)?`)
)
View Source
var (
	// MarkupName describes markup's name
	MarkupName = "markdown"
)

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 InitMarkdown added in v1.1.4

func InitMarkdown()

InitMarkdown initialize regexps for markdown parsing

func IsMarkdownFile

func IsMarkdownFile(name string) bool

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

func IsSameDomain added in v1.1.0

func IsSameDomain(s string) bool

IsSameDomain checks if given url string has the same hostname as current Gitea instance

func NewSanitizer added in v1.1.1

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 PostProcess

func PostProcess(rawHTML []byte, urlPrefix string, metas map[string]string, isWikiMarkdown bool) []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 all specific handling stuff.

func RenderCrossReferenceIssueIndexPattern added in v1.1.0

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

RenderCrossReferenceIssueIndexPattern renders issue indexes from other repositories to corresponding links.

func RenderFullIssuePattern added in v1.1.4

func RenderFullIssuePattern(rawBytes []byte) []byte

RenderFullIssuePattern renders issues-like URLs

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, wikiMarkdown bool) []byte

RenderRaw renders Markdown to HTML without handling special links.

func RenderShortLinks(rawBytes []byte, urlPrefix string, noLink bool, isWikiMarkdown bool) []byte

RenderShortLinks processes [[syntax]]

noLink flag disables making link tags when set to true so this function just replaces the whole [[...]] with the content text

isWikiMarkdown is a flag to choose linking url prefix

func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]string, isWikiMarkdown bool) []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.

func RenderWiki added in v1.1.0

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

RenderWiki renders markdown wiki page to HTML and return HTML string

func Sanitize added in v1.1.1

func Sanitize(s string) string

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

func SanitizeBytes added in v1.1.1

func SanitizeBytes(b []byte) []byte

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

func URLJoin added in v1.1.0

func URLJoin(base string, elems ...string) string

URLJoin joins url components, like path.Join, but preserving contents

Types

type Parser added in v1.2.0

type Parser struct {
}

Parser implements markup.Parser

func (Parser) Extensions added in v1.2.0

func (Parser) Extensions() []string

Extensions implements markup.Parser

func (Parser) Name added in v1.2.0

func (Parser) Name() string

Name implements markup.Parser

func (Parser) Render added in v1.2.0

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

Render implements markup.Parser

type Renderer

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

Renderer is a extended version of underlying render object.

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) List added in v1.1.0

func (r *Renderer) List(out *bytes.Buffer, text func() bool, flags int)

List renders markdown bullet or digit lists to HTML

func (*Renderer) ListItem

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

Jump to

Keyboard shortcuts

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