Documentation
¶
Index ¶
- Constants
- Variables
- func CamoEncode(link string) string
- func ComposeSimpleDocumentMetas() map[string]string
- func CustomLinkURLSchemes(schemes []string)
- func DetectRendererTypeByPrefetch(filename string, sniffedType typesniffer.SniffedType, prefetchBuf []byte) string
- func Init(renderHelpFuncs *RenderHelperFuncs)
- func IsFullURLString(link string) bool
- func IsNonEmptyRelativePath(link string) bool
- func ParseRenderedLink(s, preferLinkType string) (linkType, link string)
- func PostProcessCommitMessage(ctx *RenderContext, content template.HTML) template.HTML
- func PostProcessCommitMessageSubject(ctx *RenderContext, defaultLink string, content template.HTML) template.HTML
- func PostProcessDefault(ctx *RenderContext, input io.Reader, output io.Writer) error
- func PostProcessDescriptionHTML(ctx *RenderContext, content template.HTML) template.HTML
- func PostProcessEmoji(ctx *RenderContext, content template.HTML) template.HTML
- func PostProcessIssueTitle(ctx *RenderContext, titleHTML template.HTML) template.HTML
- func PreviewableExtensions() []string
- func RefreshFileNamePatterns()
- func RegisterRenderer(renderer Renderer)
- func Render(rctx *RenderContext, origInput io.Reader, output io.Writer) error
- func RenderIFrame(ctx *RenderContext, opts *ExternalRendererOptions, output io.Writer) error
- func RenderTocHeadingItems(ctx *RenderContext, nodeDetailsAttrs map[string]string, out io.Writer)
- func RenderWithRenderer(ctx *RenderContext, renderer Renderer, input io.Reader, output io.Writer) error
- func RendererNeedPostProcess(renderer Renderer) bool
- func ResetDefaultSanitizerForTesting()
- func Sanitize(s string) template.HTML
- func SanitizeDescription(s string) string
- func SanitizeReader(r io.Reader, renderer string, w io.Writer) error
- type ExternalRenderer
- type ExternalRendererOptions
- type PostProcessRenderer
- type RenderCodePreviewOptions
- type RenderContext
- func (ctx *RenderContext) Deadline() (deadline time.Time, ok bool)
- func (ctx *RenderContext) DetectMarkupRenderer(prefetchBuf []byte) Renderer
- func (ctx *RenderContext) DetectMarkupRendererByReader(in io.Reader) (Renderer, io.Reader, error)
- func (ctx *RenderContext) Done() <-chan struct{}
- func (ctx *RenderContext) Err() error
- func (ctx *RenderContext) ResolveLinkRelative(base, cur, link string) string
- func (ctx *RenderContext) ResolveLinkRoot(link string) string
- func (ctx *RenderContext) Value(key any) any
- func (ctx *RenderContext) WithEnableHeadingIDGeneration(v bool) *RenderContext
- func (ctx *RenderContext) WithHelper(helper RenderHelper) *RenderContext
- func (ctx *RenderContext) WithMarkupType(typ string) *RenderContext
- func (ctx *RenderContext) WithMetas(metas map[string]string) *RenderContext
- func (ctx *RenderContext) WithRelativePath(path string) *RenderContext
- func (ctx *RenderContext) WithStandalonePage(opts StandalonePageOptions) *RenderContext
- func (ctx *RenderContext) WithUseAbsoluteLink(v bool) *RenderContext
- type RenderHelper
- type RenderHelperFuncs
- type RenderIssueIconTitleOptions
- type RenderMetaMode
- type RenderOptions
- type Renderer
- type RendererContentDetector
- type Sanitizer
- type SimpleRenderHelper
- type StandalonePageOptions
- type TestRenderHelper
- type TocHeadingItem
- type TocShowInSectionType
- type WebThemeInterface
Constants ¶
const ( IssueNameStyleNumeric = "numeric" IssueNameStyleAlphanumeric = "alphanumeric" IssueNameStyleRegexp = "regexp" )
Issue name styles
const ( LinkTypeDefault = "" LinkTypeRoot = "/:root" // the link is relative to the AppSubURL(ROOT_URL) LinkTypeMedia = "/:media" // the link should be used to access media files (images, videos) LinkTypeRaw = "/:raw" // not really useful, mainly for environment GIT_PREFIX_RAW for external renders )
Variables ¶
var RenderBehaviorForTesting struct { // Gitea will emit some additional attributes for various purposes, these attributes don't affect rendering. // But there are too many hard-coded test cases, to avoid changing all of them again and again, we can disable emitting these internal attributes. DisableAdditionalAttributes bool }
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 DetectRendererTypeByPrefetch ¶
func DetectRendererTypeByPrefetch(filename string, sniffedType typesniffer.SniffedType, prefetchBuf []byte) string
DetectRendererTypeByPrefetch detects the markup type of the content
func Init ¶
func Init(renderHelpFuncs *RenderHelperFuncs)
Init initializes the render global variables
func IsFullURLString ¶
func IsNonEmptyRelativePath ¶
func ParseRenderedLink ¶
func PostProcessCommitMessage ¶
func PostProcessCommitMessage(ctx *RenderContext, content template.HTML) template.HTML
PostProcessCommitMessage will use the same logic as PostProcess, but will disable the shortLinkProcessor.
func PostProcessCommitMessageSubject ¶
func PostProcessCommitMessageSubject(ctx *RenderContext, defaultLink string, content template.HTML) template.HTML
PostProcessCommitMessageSubject will use the same logic as PostProcess and PostProcessCommitMessage, but will disable the shortLinkProcessor and emailAddressProcessor, and wraps the whole subject in defaultLink.
func PostProcessDefault ¶
PostProcessDefault 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 PostProcessDescriptionHTML ¶
func PostProcessDescriptionHTML(ctx *RenderContext, content template.HTML) template.HTML
PostProcessDescriptionHTML will use similar logic as PostProcess, but will use a single special linkProcessor.
func PostProcessEmoji ¶
func PostProcessEmoji(ctx *RenderContext, content template.HTML) template.HTML
PostProcessEmoji for when we want to just process emoji and shortcodes in various places it isn't already run through the normal Markdown processor
func PostProcessIssueTitle ¶
func PostProcessIssueTitle(ctx *RenderContext, titleHTML template.HTML) template.HTML
PostProcessIssueTitle to process title on individual issue/pull page
func PreviewableExtensions ¶
func PreviewableExtensions() []string
func RefreshFileNamePatterns ¶
func RefreshFileNamePatterns()
func RegisterRenderer ¶
func RegisterRenderer(renderer Renderer)
RegisterRenderer registers a new markup file renderer
func RenderIFrame ¶
func RenderIFrame(ctx *RenderContext, opts *ExternalRendererOptions, output io.Writer) error
func RenderTocHeadingItems ¶
func RenderTocHeadingItems(ctx *RenderContext, nodeDetailsAttrs map[string]string, out io.Writer)
func RenderWithRenderer ¶
func RendererNeedPostProcess ¶
func ResetDefaultSanitizerForTesting ¶
func ResetDefaultSanitizerForTesting()
func SanitizeDescription ¶
SanitizeDescription sanitizes the HTML generated for a repository description.
Types ¶
type ExternalRenderer ¶
type ExternalRenderer interface {
GetExternalRendererOptions() ExternalRendererOptions
}
ExternalRenderer defines an interface for external renderers
type ExternalRendererOptions ¶
type ExternalRendererOptions struct {
SanitizerDisabled bool
DisplayInIframe bool
ContentSandbox string
}
func GetExternalRendererOptions ¶
func GetExternalRendererOptions(renderer Renderer) (ret ExternalRendererOptions, _ bool)
type PostProcessRenderer ¶
type PostProcessRenderer interface {
NeedPostProcess() bool
}
PostProcessRenderer defines an interface for renderers who need post process
type RenderContext ¶
type RenderContext struct {
TocShowInSection TocShowInSectionType
TocHeadingItems []*TocHeadingItem
RenderHelper RenderHelper
RenderOptions RenderOptions
RenderInternal internal.RenderInternal
// contains filtered or unexported fields
}
RenderContext represents a render context
func NewRenderContext ¶
func NewRenderContext(ctx context.Context) *RenderContext
func NewTestRenderContext ¶
func NewTestRenderContext(baseLinkOrMetas ...any) *RenderContext
NewTestRenderContext is a helper function to create a RenderContext for testing purpose It accepts string (BaseLink), map[string]string (Metas)
func (*RenderContext) DetectMarkupRenderer ¶
func (ctx *RenderContext) DetectMarkupRenderer(prefetchBuf []byte) Renderer
func (*RenderContext) DetectMarkupRendererByReader ¶
func (*RenderContext) Done ¶
func (ctx *RenderContext) Done() <-chan struct{}
func (*RenderContext) Err ¶
func (ctx *RenderContext) Err() error
func (*RenderContext) ResolveLinkRelative ¶
func (ctx *RenderContext) ResolveLinkRelative(base, cur, link string) string
func (*RenderContext) ResolveLinkRoot ¶
func (ctx *RenderContext) ResolveLinkRoot(link string) string
func (*RenderContext) Value ¶
func (ctx *RenderContext) Value(key any) any
func (*RenderContext) WithEnableHeadingIDGeneration ¶
func (ctx *RenderContext) WithEnableHeadingIDGeneration(v bool) *RenderContext
func (*RenderContext) WithHelper ¶
func (ctx *RenderContext) WithHelper(helper RenderHelper) *RenderContext
func (*RenderContext) WithMarkupType ¶
func (ctx *RenderContext) WithMarkupType(typ string) *RenderContext
func (*RenderContext) WithMetas ¶
func (ctx *RenderContext) WithMetas(metas map[string]string) *RenderContext
func (*RenderContext) WithRelativePath ¶
func (ctx *RenderContext) WithRelativePath(path string) *RenderContext
func (*RenderContext) WithStandalonePage ¶
func (ctx *RenderContext) WithStandalonePage(opts StandalonePageOptions) *RenderContext
func (*RenderContext) WithUseAbsoluteLink ¶
func (ctx *RenderContext) WithUseAbsoluteLink(v bool) *RenderContext
type RenderHelper ¶
type RenderHelperFuncs ¶
type RenderHelperFuncs struct {
IsUsernameMentionable func(ctx context.Context, username string) bool
RenderRepoFileCodePreview func(ctx context.Context, options RenderCodePreviewOptions) (template.HTML, error)
RenderRepoIssueIconTitle func(ctx context.Context, options RenderIssueIconTitleOptions) (template.HTML, error)
}
RenderHelperFuncs is used to decouple cycle-import At the moment there are different packages: modules/markup: basic markup rendering models/renderhelper: need to access models and git repo, and models/issues needs it services/markup: some real helper functions could only be provided here because it needs to access various services & templates
var DefaultRenderHelperFuncs *RenderHelperFuncs
type RenderMetaMode ¶
type RenderMetaMode string
const ( RenderMetaAsDetails RenderMetaMode = "details" // default RenderMetaAsNone RenderMetaMode = "none" RenderMetaAsTable RenderMetaMode = "table" )
type RenderOptions ¶
type RenderOptions struct {
UseAbsoluteLink bool
// relative path from tree root of the branch
RelativePath string
// eg: "orgmode", "asciicast", "console"
// for file mode, it could be left as empty, and will be detected by file extension in RelativePath
MarkupType string
// user&repo, format&style®exp (for external issue pattern), teams&org (for mention)
// RefTypeNameSubURL (for iframe&asciicast)
// markupAllowShortIssuePattern
// markdownNewLineHardBreak
Metas map[string]string
// used by external render. the router "/org/repo/render/..." will output the rendered content in a standalone page
StandalonePageOptions *StandalonePageOptions
// EnableHeadingIDGeneration controls whether to auto-generate IDs for HTML headings without id attribute.
// This should be enabled for repository files and wiki pages, but disabled for comments to avoid duplicate IDs.
EnableHeadingIDGeneration bool
}
type Renderer ¶
type Renderer interface {
Name() string // markup format name, also the renderer type, also the external tool name
FileNamePatterns() []string
SanitizerRules() []setting.MarkupSanitizerRule
Render(ctx *RenderContext, input io.Reader, output io.Writer) error
}
Renderer defines an interface for rendering markup file to HTML
type RendererContentDetector ¶
type RendererContentDetector interface {
CanRender(filename string, sniffedType typesniffer.SniffedType, prefetchBuf []byte) bool
}
RendererContentDetector detects if the content can be rendered by specified renderer
type Sanitizer ¶
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 ¶
func GetDefaultSanitizer() *Sanitizer
type SimpleRenderHelper ¶
type SimpleRenderHelper struct{}
func (*SimpleRenderHelper) CleanUp ¶
func (r *SimpleRenderHelper) CleanUp()
func (*SimpleRenderHelper) IsCommitIDExisting ¶
func (r *SimpleRenderHelper) IsCommitIDExisting(commitID string) bool
func (*SimpleRenderHelper) ResolveLink ¶
func (r *SimpleRenderHelper) ResolveLink(link, preferLinkType string) string
type StandalonePageOptions ¶
type StandalonePageOptions struct {
CurrentWebTheme WebThemeInterface
RenderQueryString string
}
type TestRenderHelper ¶
type TestRenderHelper struct {
BaseLink string
// contains filtered or unexported fields
}
func (*TestRenderHelper) CleanUp ¶
func (r *TestRenderHelper) CleanUp()
func (*TestRenderHelper) IsCommitIDExisting ¶
func (r *TestRenderHelper) IsCommitIDExisting(commitID string) bool
func (*TestRenderHelper) ResolveLink ¶
func (r *TestRenderHelper) ResolveLink(link, preferLinkType string) string
type TocHeadingItem ¶
type TocShowInSectionType ¶
type TocShowInSectionType string
const ( TocShowInSidebar TocShowInSectionType = "sidebar" TocShowInMain TocShowInSectionType = "main" )
type WebThemeInterface ¶
type WebThemeInterface interface {
PublicAssetURI() string
}