Documentation ¶
Index ¶
- Constants
- Variables
- func CamoEncode(link string) string
- func CustomLinkURLSchemes(schemes []string)
- func DetectRendererType(filename string, input io.Reader) string
- func Init(ph *ProcessorHelper)
- func InitializeSanitizer()
- func IsErrUnsupportedRenderExtension(err error) bool
- func IsLink(link []byte) bool
- func IsMarkupFile(name, markup string) bool
- func IsSameDomain(s string) bool
- func NewSanitizer()
- func PostProcess(ctx *RenderContext, input io.Reader, output io.Writer) error
- func PreviewableExtensions() []string
- func RegisterRenderer(renderer Renderer)
- func Render(ctx *RenderContext, input io.Reader, output io.Writer) error
- func RenderCommitMessage(ctx *RenderContext, content string) (string, error)
- func RenderCommitMessageSubject(ctx *RenderContext, content string) (string, error)
- func RenderDescriptionHTML(ctx *RenderContext, content string) (string, error)
- func RenderEmoji(ctx *RenderContext, content string) (string, error)
- func RenderIssueTitle(ctx *RenderContext, title string) (string, error)
- func RenderString(ctx *RenderContext, content string) (string, error)
- func Sanitize(s string) string
- func SanitizeReader(r io.Reader, renderer string, w io.Writer) error
- func Type(filename string) string
- type ErrUnsupportedRenderExtension
- type ErrUnsupportedRenderType
- type ExternalRenderer
- type Header
- type PostProcessRenderer
- type ProcessorHelper
- type RenderContext
- type RenderMetaMode
- type Renderer
- type RendererContentDetector
- type Sanitizer
Constants ¶
const ( IssueNameStyleNumeric = "numeric" IssueNameStyleAlphanumeric = "alphanumeric" IssueNameStyleRegexp = "regexp" )
Issue name styles
Variables ¶
var ( // EmojiShortCodeRegex find emoji by alias like :smile: EmojiShortCodeRegex = regexp.MustCompile(`:[-+\w]+:`) )
Functions ¶
func CamoEncode ¶
CamoEncode encodes a lnk to fit with the go-camo and camo proxy links. The purposes of camo-proxy are: 1. Allow accessing "http://" images on a HTTPS site by using the "https://" URLs provided by camo-proxy. 2. Hide the visitor's real IP (protect privacy) when accessing external images.
func CustomLinkURLSchemes ¶
func CustomLinkURLSchemes(schemes []string)
CustomLinkURLSchemes allows for additional schemes to be detected when parsing links within text
func DetectRendererType ¶
DetectRendererType detects the markup type of the content
func InitializeSanitizer ¶
func InitializeSanitizer()
InitializeSanitizer (re)initializes the current sanitizer to account for changes in settings
func IsMarkupFile ¶
IsMarkupFile reports whether file is a markup type file
func IsSameDomain ¶
IsSameDomain checks if given url string has the same hostname as current Gitea instance
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 PostProcess ¶
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 PreviewableExtensions ¶
func PreviewableExtensions() []string
func RegisterRenderer ¶
func RegisterRenderer(renderer Renderer)
RegisterRenderer registers a new markup file renderer
func RenderCommitMessage ¶
func RenderCommitMessage( ctx *RenderContext, content string, ) (string, 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 ¶
func RenderCommitMessageSubject( ctx *RenderContext, content string, ) (string, 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 ¶
func RenderDescriptionHTML( ctx *RenderContext, content string, ) (string, error)
RenderDescriptionHTML will use similar logic as PostProcess, but will use a single special linkProcessor.
func RenderEmoji ¶
func RenderEmoji( ctx *RenderContext, content string, ) (string, error)
RenderEmoji for when we want to just process emoji and shortcodes in various places it isn't already run through the normal markdown processor
func RenderIssueTitle ¶
func RenderIssueTitle( ctx *RenderContext, title string, ) (string, error)
RenderIssueTitle to process title on individual issue/pull page
func RenderString ¶
func RenderString(ctx *RenderContext, content string) (string, error)
RenderString renders Markup string to HTML with all specific handling stuff and return string
func Sanitize ¶
Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.
func SanitizeReader ¶
SanitizeReader sanitizes a Reader
Types ¶
type ErrUnsupportedRenderExtension ¶
type ErrUnsupportedRenderExtension struct {
Extension string
}
ErrUnsupportedRenderExtension represents the error when extension doesn't supported to render
func (ErrUnsupportedRenderExtension) Error ¶
func (err ErrUnsupportedRenderExtension) Error() string
type ErrUnsupportedRenderType ¶
type ErrUnsupportedRenderType struct {
Type string
}
ErrUnsupportedRenderType represents
func (ErrUnsupportedRenderType) Error ¶
func (err ErrUnsupportedRenderType) Error() string
type ExternalRenderer ¶
type ExternalRenderer interface { // SanitizerDisabled disabled sanitize if return true SanitizerDisabled() bool // DisplayInIFrame represents whether render the content with an iframe DisplayInIFrame() bool }
PostProcessRenderer defines an interface for external renderers
type PostProcessRenderer ¶
type PostProcessRenderer interface {
NeedPostProcess() bool
}
PostProcessRenderer defines an interface for renderers who need post process
type ProcessorHelper ¶
type ProcessorHelper struct { IsUsernameMentionable func(ctx context.Context, username string) bool ElementDir string // the direction of the elements, eg: "ltr", "rtl", "auto", default to no direction attribute }
var DefaultProcessorHelper ProcessorHelper
type RenderContext ¶
type RenderContext struct { Ctx context.Context RelativePath string // relative path from tree root of the branch Type string IsWiki bool URLPrefix string Metas map[string]string DefaultLink string GitRepo *git.Repository ShaExistCache map[string]bool SidebarTocNode ast.Node RenderMetaAs RenderMetaMode InStandalonePage bool // used by external render. the router "/org/repo/render/..." will output the rendered content in a standalone page // contains filtered or unexported fields }
RenderContext represents a render context
func (*RenderContext) AddCancel ¶
func (ctx *RenderContext) AddCancel(fn func())
AddCancel adds the provided fn as a Cleanup for this Ctx
func (*RenderContext) Cancel ¶
func (ctx *RenderContext) Cancel()
Cancel runs any cleanup functions that have been registered for this Ctx
type RenderMetaMode ¶
type RenderMetaMode string
const ( RenderMetaAsDetails RenderMetaMode = "details" // default RenderMetaAsNone RenderMetaMode = "none" RenderMetaAsTable RenderMetaMode = "table" )
type Renderer ¶
type Renderer interface { Name() string // markup format name Extensions() []string SanitizerRules() []setting.MarkupSanitizerRule Render(ctx *RenderContext, input io.Reader, output io.Writer) error }
Renderer defines an interface for rendering markup file to HTML
func GetRendererByFileName ¶
GetRendererByFileName get renderer by filename
func GetRendererByType ¶
GetRendererByType returns a renderer according type
type RendererContentDetector ¶
RendererContentDetector detects if the content can be rendered by specified renderer