Documentation ¶
Index ¶
- Constants
- Variables
- func BuildSanitizer()
- func FindAllMentions(content string) []string
- func IsMarkdownFile(name string) bool
- func IsReadmeFile(name string) bool
- func IsSameDomain(s string) bool
- func PostProcess(rawHTML []byte, urlPrefix string, metas map[string]string, isWikiMarkdown bool) []byte
- func Render(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderCrossReferenceIssueIndexPattern(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, wikiMarkdown bool) []byte
- func RenderShortLinks(rawBytes []byte, urlPrefix string, noLink bool, isWikiMarkdown bool) []byte
- func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]string, ...) []byte
- func RenderString(raw, urlPrefix string, metas map[string]string) string
- func RenderWiki(rawBytes []byte, urlPrefix string, metas map[string]string) string
- func URLJoin(elem ...string) string
- type Renderer
- 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 (r *Renderer) List(out *bytes.Buffer, text func() bool, flags int)
- func (r *Renderer) ListItem(out *bytes.Buffer, text []byte, flags int)
Constants ¶
const ( IssueNameStyleNumeric = "numeric" IssueNameStyleAlphanumeric = "alphanumeric" )
Issue name styles
Variables ¶
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 // 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(`(?:^|\s|\()[0-9a-f]{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+))?)?`) // IssueFullPattern allows to split issue (and pull) URLs into parts IssueFullPattern = regexp.MustCompile(`(?:^|\s|\()(http\S*)://((?:[^\s/]+/)+)((?:\w{1,10}-)?[1-9][0-9]*)([\?|#]\S+.(\S+)?)?\b`) )
var Sanitizer = bluemonday.UGCPolicy()
Sanitizer markdown sanitizer
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 ¶
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 name.
func IsSameDomain ¶ added in v1.1.0
IsSameDomain checks if given url string has the same hostname as current Gitea instance
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 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 RenderIssueIndexPattern ¶
RenderIssueIndexPattern renders issue indexes to corresponding links.
func RenderShortLinks ¶ added in v1.1.0
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 ¶
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 ¶
RenderString renders Markdown to HTML with special links and returns string type.
func RenderWiki ¶ added in v1.1.0
RenderWiki renders markdown wiki page to HTML and return HTML string
Types ¶
type Renderer ¶
type Renderer struct { blackfriday.Renderer // contains filtered or unexported fields }
Renderer is a extended version of underlying render object.
func (*Renderer) Image ¶
Image defines how images should be processed to produce corresponding HTML elements.
func (*Renderer) Link ¶
Link defines how formal links should be processed to produce corresponding HTML elements.