Documentation ¶
Index ¶
- Constants
- Variables
- func BuildSanitizer()
- func FindAllMentions(content string) []string
- func IsMarkdownFile(name string) bool
- func IsReadmeFile(name string) bool
- func PostProcess(rawHtml []byte, urlPrefix string, metas map[string]string) []byte
- func Render(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderRaw(body []byte, urlPrefix string) []byte
- func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte
- func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderString(raw, urlPrefix string, metas map[string]string) string
- type Renderer
- func (r *Renderer) AutoLink(out *bytes.Buffer, link []byte, kind int)
- func (r *Renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte)
- func (r *Renderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte)
- func (options *Renderer) ListItem(out *bytes.Buffer, text []byte, flags int)
Constants ¶
const ( ISSUE_NAME_STYLE_NUMERIC = "numeric" ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric" )
Variables ¶
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`) )
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
FindAllMentions matches mention patterns in given content and returns a list of found user names without @ prefix.
func IsMarkdownFile ¶
IsMarkdownFile reports whether name looks like a Markdown file based on its extension.
func IsReadmeFile ¶
IsReadmeFile reports whether name looks like a README file based on its extension.
func PostProcess ¶
PostProcess treats different types of HTML differently, and only renders special links for plain text blocks.
func RenderIssueIndexPattern ¶
RenderIssueIndexPattern renders issue indexes to corresponding links.
func RenderSha1CurrentPattern ¶
RenderSha1CurrentPattern renders SHA1 strings to corresponding links that assumes in the same repository.
func RenderSpecialLink ¶
RenderSpecialLink renders mentions, indexes and SHA1 strings to corresponding links.
Types ¶
type Renderer ¶
type Renderer struct { blackfriday.Renderer // contains filtered or unexported fields }
Renderer is a extended version of underlying render object.
func (*Renderer) AutoLink ¶
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 ¶
Image defines how images should be processed to produce corresponding HTML elements.