Documentation ¶
Index ¶
- Constants
- func Init()
- func IsLink(link []byte) bool
- func IsMarkupFile(name, markup string) bool
- func IsReadmeFile(name string, ext ...string) bool
- func IsSameDomain(s string) bool
- func NewSanitizer()
- func PostProcess(rawHTML []byte, urlPrefix string, metas map[string]string, isWikiMarkdown bool) ([]byte, error)
- 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 RenderCommitMessage(rawHTML []byte, urlPrefix, defaultLink string, metas map[string]string) ([]byte, error)
- func RenderCommitMessageSubject(rawHTML []byte, urlPrefix, defaultLink string, metas map[string]string) ([]byte, error)
- func RenderDescriptionHTML(rawHTML []byte, urlPrefix string, metas map[string]string) ([]byte, error)
- 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
- type Parser
- type Sanitizer
Constants ¶
const ( IssueNameStyleNumeric = "numeric" IssueNameStyleAlphanumeric = "alphanumeric" )
Issue name styles
Variables ¶
This section is empty.
Functions ¶
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. If an extension is provided, it will strictly match that extension. Note that the '.' should be provided in ext, e.g ".md"
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, error)
PostProcess does the final required transformations to the passed raw HTML data, and ensures its validity. Transformations include: replacing links and emails with HTML links, parsing shortlinks in the format of [[Link]], like MediaWiki, linking issues in the format #ID, and mentions in the format @user, and others.
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 RenderCommitMessage ¶ added in v1.5.0
func RenderCommitMessage( rawHTML []byte, urlPrefix, defaultLink string, metas map[string]string, ) ([]byte, error)
RenderCommitMessage will use the same logic as PostProcess, but will disable the shortLinkProcessor and will add a defaultLinkProcessor if defaultLink is set, which changes every text node into a link to the passed default link.
func RenderCommitMessageSubject ¶ added in v1.10.0
func RenderCommitMessageSubject( rawHTML []byte, urlPrefix, defaultLink string, metas map[string]string, ) ([]byte, error)
RenderCommitMessageSubject will use the same logic as PostProcess and RenderCommitMessage, but will disable the shortLinkProcessor and emailAddressProcessor, will add a defaultLinkProcessor if defaultLink is set, which changes every text node into a link to the passed default link.
func RenderDescriptionHTML ¶ added in v1.7.4
func RenderDescriptionHTML( rawHTML []byte, urlPrefix string, metas map[string]string, ) ([]byte, error)
RenderDescriptionHTML will use similar logic as PostProcess, but will use a single special linkProcessor.
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