markup

package
v0.11.66 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2018 License: MIT Imports: 16 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|^|\W)@[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`)
	// CrossReferenceIssueNumericPattern matches string that references a numeric issue in a difference repository
	// e.g. gogs/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
	// 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]{7,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 IsIPythonNotebook added in v0.11.19

func IsIPythonNotebook(name string) bool

IsIPythonNotebook reports whether name looks like a IPython notebook based on its extension.

func IsMarkdownFile

func IsMarkdownFile(name string) bool

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

func IsOrgModeFile added in v0.11.19

func IsOrgModeFile(name string) bool

IsOrgModeFile reports whether name looks like a Org-mode 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, metas map[string]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 OrgMode added in v0.11.19

func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte

OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links.

func RawMarkdown

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

RawMarkdown renders content in Markdown syntax to HTML without handling special links.

func RawOrgMode added in v0.11.19

func RawOrgMode(body []byte, urlPrefix string) (result []byte)

RawOrgMode renders content in Org-mode syntax to HTML without handling special links.

func Render

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

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

func RenderCrossReferenceIssueIndexPattern

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

RenderCrossReferenceIssueIndexPattern renders issue indexes from other repositories to corresponding links.

func RenderIssueIndexPattern

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

RenderIssueIndexPattern renders issue indexes to corresponding 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 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 (options *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
const (
	UNRECOGNIZED     Type = "unrecognized"
	MARKDOWN         Type = "markdown"
	ORG_MODE         Type = "orgmode"
	IPYTHON_NOTEBOOK Type = "ipynb"
)

func Detect added in v0.11.19

func Detect(filename string) Type

Detect returns best guess of a markup type based on file name.

Jump to

Keyboard shortcuts

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