Documentation ¶
Index ¶
- Constants
- func CamoEncode(link string) string
- func CustomLinkURLSchemes(schemes []string)
- func DetectMarkupTypeByFileName(filename string) string
- func DetectRendererType(filename string, input io.Reader) string
- func Init(ph *ProcessorHelper)
- func IsErrUnsupportedRenderExtension(err error) bool
- func IsFullURLBytes(link []byte) bool
- func IsFullURLString(link string) bool
- func IsNonEmptyRelativePath(link string) bool
- func IsSameDomain(s string) bool
- 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 ResetDefaultSanitizerForTesting()
- func ResolveLink(ctx *RenderContext, link, userContentAnchorPrefix string) (result string, resolved bool)
- func Sanitize(s string) string
- func SanitizeDescription(s string) string
- func SanitizeReader(r io.Reader, renderer string, w io.Writer) error
- type ErrUnsupportedRenderExtension
- type ErrUnsupportedRenderType
- type ExternalRenderer
- type Header
- type Links
- type PostProcessRenderer
- type ProcessorHelper
- type RenderCodePreviewOptions
- type RenderContext
- type RenderMetaMode
- type Renderer
- type RendererContentDetector
- type Sanitizer
Constants ¶
const ( IssueNameStyleNumeric = "numeric" IssueNameStyleAlphanumeric = "alphanumeric" IssueNameStyleRegexp = "regexp" )
Issue name styles
Variables ¶
This section is empty.
Functions ¶
func CamoEncode ¶ added in v1.17.0
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 ¶ added in v1.11.0
func CustomLinkURLSchemes(schemes []string)
CustomLinkURLSchemes allows for additional schemes to be detected when parsing links within text
func DetectMarkupTypeByFileName ¶ added in v1.22.1
DetectMarkupTypeByFileName returns the possible markup format type via the filename
func DetectRendererType ¶ added in v1.17.0
DetectRendererType detects the markup type of the content
func Init ¶ added in v1.3.0
func Init(ph *ProcessorHelper)
Init initialize regexps for markdown parsing
func IsErrUnsupportedRenderExtension ¶ added in v1.20.0
func IsFullURLBytes ¶ added in v1.22.0
IsFullURLBytes reports whether link fits valid format.
func IsFullURLString ¶ added in v1.22.0
func IsNonEmptyRelativePath ¶ added in v1.22.1
func IsSameDomain ¶ added in v1.3.0
IsSameDomain checks if given url string has the same hostname as current Gitea instance
func PostProcess ¶ added in v1.3.0
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 ¶ added in v1.20.0
func PreviewableExtensions() []string
func RegisterRenderer ¶ added in v1.15.0
func RegisterRenderer(renderer Renderer)
RegisterRenderer registers a new markup file renderer
func RenderCommitMessage ¶ added in v1.5.0
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 ¶ added in v1.10.0
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 ¶ added in v1.7.4
func RenderDescriptionHTML( ctx *RenderContext, content string, ) (string, error)
RenderDescriptionHTML will use similar logic as PostProcess, but will use a single special linkProcessor.
func RenderEmoji ¶ added in v1.12.0
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 ¶ added in v1.14.0
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 ResetDefaultSanitizerForTesting ¶ added in v1.22.1
func ResetDefaultSanitizerForTesting()
func ResolveLink ¶ added in v1.22.1
func ResolveLink(ctx *RenderContext, link, userContentAnchorPrefix string) (result string, resolved bool)
func Sanitize ¶ added in v1.3.0
Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.
func SanitizeDescription ¶ added in v1.22.0
SanitizeDescription sanitizes the HTML generated for a repository description.
Types ¶
type ErrUnsupportedRenderExtension ¶ added in v1.15.0
type ErrUnsupportedRenderExtension struct {
Extension string
}
ErrUnsupportedRenderExtension represents the error when extension doesn't supported to render
func (ErrUnsupportedRenderExtension) Error ¶ added in v1.15.0
func (err ErrUnsupportedRenderExtension) Error() string
type ErrUnsupportedRenderType ¶ added in v1.15.0
type ErrUnsupportedRenderType struct {
Type string
}
ErrUnsupportedRenderType represents
func (ErrUnsupportedRenderType) Error ¶ added in v1.15.0
func (err ErrUnsupportedRenderType) Error() string
type ExternalRenderer ¶ added in v1.17.0
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 Links ¶ added in v1.21.4
type Links struct { AbsolutePrefix bool // add absolute URL prefix to auto-resolved links like "#issue", but not for pre-provided links and medias Base string // base prefix for pre-provided links and medias (images, videos) BranchPath string // actually it is the ref path, eg: "branch/features/feat-12", "tag/v1.0" TreePath string // the dir of the file, eg: "doc" if the file "doc/CHANGE.md" is being rendered }
func (*Links) HasBranchInfo ¶ added in v1.21.4
func (*Links) ResolveMediaLink ¶ added in v1.21.4
func (*Links) WikiRawLink ¶ added in v1.21.4
type PostProcessRenderer ¶ added in v1.17.0
type PostProcessRenderer interface {
NeedPostProcess() bool
}
PostProcessRenderer defines an interface for renderers who need post process
type ProcessorHelper ¶ added in v1.17.4
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 RenderRepoFileCodePreview func(ctx context.Context, options RenderCodePreviewOptions) (template.HTML, error) }
var DefaultProcessorHelper ProcessorHelper
type RenderCodePreviewOptions ¶ added in v1.22.0
type RenderContext ¶ added in v1.15.0
type RenderContext struct { Ctx context.Context RelativePath string // relative path from tree root of the branch Type string IsWiki bool Links Links Metas map[string]string // user, repo, mode(comment/document) 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 ¶ added in v1.15.0
func (ctx *RenderContext) AddCancel(fn func())
AddCancel adds the provided fn as a Cleanup for this Ctx
func (*RenderContext) Cancel ¶ added in v1.15.0
func (ctx *RenderContext) Cancel()
Cancel runs any cleanup functions that have been registered for this Ctx
type RenderMetaMode ¶ added in v1.20.0
type RenderMetaMode string
const ( RenderMetaAsDetails RenderMetaMode = "details" // default RenderMetaAsNone RenderMetaMode = "none" RenderMetaAsTable RenderMetaMode = "table" )
type Renderer ¶ added in v1.15.0
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 ¶ added in v1.15.0
GetRendererByFileName get renderer by filename
func GetRendererByType ¶ added in v1.15.0
GetRendererByType returns a renderer according type
type RendererContentDetector ¶ added in v1.17.0
RendererContentDetector detects if the content can be rendered by specified renderer
type Sanitizer ¶ added in v1.3.0
type Sanitizer struct {
// contains filtered or unexported fields
}
Sanitizer is a protection wrapper of *bluemonday.Policy which does not allow any modification to the underlying policies once it's been created.
func GetDefaultSanitizer ¶ added in v1.22.1
func GetDefaultSanitizer() *Sanitizer