Documentation ¶
Index ¶
- Constants
- Variables
- func FindAllMentions(content string) []string
- func Init()
- func IsLink(link []byte) bool
- func IsMarkupFile(name, markup string) bool
- func IsReadmeFile(name string) bool
- func IsSameDomain(s string) bool
- func NewSanitizer()
- func PostProcess(rawHTML []byte, urlPrefix string, metas map[string]string, isWikiMarkdown bool) []byte
- func RegisterParser(parser Parser)
- func Render(filename string, rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderByType(tp string, rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderCrossReferenceIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderFullIssuePattern(rawBytes []byte) []byte
- func RenderIssueIndexPattern(rawBytes []byte, opts RenderIssueIndexPatternOptions) []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(filename string, raw, urlPrefix string, metas map[string]string) string
- func RenderWiki(filename string, rawBytes []byte, urlPrefix string, metas map[string]string) string
- func Sanitize(s string) string
- func SanitizeBytes(b []byte) []byte
- func Type(filename string) string
- func URLJoin(base string, elems ...string) string
- type Parser
- type RenderIssueIndexPatternOptions
- type Sanitizer
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 // 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+))?)?`) )
Functions ¶
func FindAllMentions ¶ added in v1.3.0
FindAllMentions matches mention patterns in given content and returns a list of found user names without @ prefix.
func IsMarkupFile ¶ added in v1.3.0
IsMarkupFile reports whether file is a markup type file
func IsReadmeFile ¶
IsReadmeFile reports whether name looks like a README file based on its name.
func IsSameDomain ¶ added in v1.3.0
IsSameDomain checks if given url string has the same hostname as current Gitea instance
func NewSanitizer ¶ added in v1.3.0
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 ¶ added in v1.3.0
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 RegisterParser ¶
func RegisterParser(parser Parser)
RegisterParser registers a new markup file parser
func RenderByType ¶ added in v1.3.0
RenderByType renders markup to HTML with special links and returns string type.
func RenderCrossReferenceIssueIndexPattern ¶ added in v1.3.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.3.0
RenderFullIssuePattern renders issues-like URLs
func RenderIssueIndexPattern ¶ added in v1.3.0
func RenderIssueIndexPattern(rawBytes []byte, opts RenderIssueIndexPatternOptions) []byte
RenderIssueIndexPattern renders issue indexes to corresponding links.
func RenderShortLinks ¶ added in v1.3.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 ¶ added in v1.3.0
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 ¶
RenderWiki renders markdown wiki page to HTML and return HTML string
func Sanitize ¶ added in v1.3.0
Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.
func SanitizeBytes ¶ added in v1.3.0
SanitizeBytes takes a []byte slice that contains a HTML fragment or document and applies policy whitelist.
Types ¶
type Parser ¶
type Parser interface { Name() string // markup format name Extensions() []string Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte }
Parser defines an interface for parsering markup file to HTML
func GetParserByFileName ¶ added in v1.3.0
GetParserByFileName get parser by filename
func GetParserByType ¶ added in v1.3.0
GetParserByType returns a parser according type
type RenderIssueIndexPatternOptions ¶ added in v1.3.0
type RenderIssueIndexPatternOptions struct { // url to which non-special formatting should be linked. If empty, // no such links will be added DefaultURL string URLPrefix string Metas map[string]string }
RenderIssueIndexPatternOptions options for RenderIssueIndexPattern function