markup

package
v1.24.0-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 34 Imported by: 452

Documentation

Index

Constants

View Source
const (
	IssueNameStyleNumeric      = "numeric"
	IssueNameStyleAlphanumeric = "alphanumeric"
	IssueNameStyleRegexp       = "regexp"
)

Issue name styles

Variables

View Source
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 added in v1.17.0

func CamoEncode(link string) string

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 ComposeSimpleDocumentMetas added in v1.23.0

func ComposeSimpleDocumentMetas() map[string]string

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

func DetectMarkupTypeByFileName(filename string) string

DetectMarkupTypeByFileName returns the possible markup format type via the filename

func DetectRendererType added in v1.17.0

func DetectRendererType(filename string, input io.Reader) string

DetectRendererType detects the markup type of the content

func Init added in v1.3.0

func Init(renderHelpFuncs *RenderHelperFuncs)

Init initializes the render global variables

func IsFullURLBytes added in v1.22.0

func IsFullURLBytes(link []byte) bool

IsFullURLBytes reports whether link fits valid format.

func IsFullURLString added in v1.22.0

func IsFullURLString(link string) bool

func IsNonEmptyRelativePath added in v1.22.1

func IsNonEmptyRelativePath(link string) bool

func PostProcessCommitMessage added in v1.23.0

func PostProcessCommitMessage(ctx *RenderContext, content string) (string, error)

PostProcessCommitMessage will use the same logic as PostProcess, but will disable the shortLinkProcessor.

func PostProcessCommitMessageSubject added in v1.23.0

func PostProcessCommitMessageSubject(ctx *RenderContext, defaultLink, content string) (string, error)

PostProcessCommitMessageSubject will use the same logic as PostProcess and PostProcessCommitMessage, 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 PostProcessDefault added in v1.23.0

func PostProcessDefault(ctx *RenderContext, input io.Reader, output io.Writer) error

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 added in v1.23.0

func PostProcessDescriptionHTML(ctx *RenderContext, content string) (string, error)

PostProcessDescriptionHTML will use similar logic as PostProcess, but will use a single special linkProcessor.

func PostProcessEmoji added in v1.23.0

func PostProcessEmoji(ctx *RenderContext, content string) (string, error)

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 added in v1.23.0

func PostProcessIssueTitle(ctx *RenderContext, title string) (string, error)

PostProcessIssueTitle to process title on individual issue/pull page

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 Render

func Render(ctx *RenderContext, input io.Reader, output io.Writer) error

Render renders markup file to HTML with all specific handling stuff.

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 Sanitize added in v1.3.0

func Sanitize(s string) string

Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.

func SanitizeDescription added in v1.22.0

func SanitizeDescription(s string) string

SanitizeDescription sanitizes the HTML generated for a repository description.

func SanitizeReader added in v1.11.0

func SanitizeReader(r io.Reader, renderer string, w io.Writer) error

SanitizeReader sanitizes a Reader

Types

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
}

ExternalRenderer defines an interface for external renderers

type LinkType added in v1.23.0

type LinkType string
const (
	LinkTypeApp     LinkType = "app"     // the link is relative to the AppSubURL
	LinkTypeDefault LinkType = "default" // the link is relative to the default base (eg: repo link, or current ref tree path)
	LinkTypeMedia   LinkType = "media"   // the link should be used to access media files (images, videos)
	LinkTypeRaw     LinkType = "raw"     // not really useful, mainly for environment GITEA_PREFIX_RAW for external renders
)

type PostProcessRenderer added in v1.17.0

type PostProcessRenderer interface {
	NeedPostProcess() bool
}

PostProcessRenderer defines an interface for renderers who need post process

type RenderCodePreviewOptions added in v1.22.0

type RenderCodePreviewOptions struct {
	FullURL   string
	OwnerName string
	RepoName  string
	CommitID  string
	FilePath  string

	LineStart, LineStop int
}

type RenderContext added in v1.15.0

type RenderContext struct {
	SidebarTocNode ast.Node

	RenderHelper   RenderHelper
	RenderOptions  RenderOptions
	RenderInternal internal.RenderInternal
	// contains filtered or unexported fields
}

RenderContext represents a render context

func NewRenderContext added in v1.23.0

func NewRenderContext(ctx context.Context) *RenderContext

func NewTestRenderContext added in v1.23.0

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) Deadline added in v1.23.0

func (ctx *RenderContext) Deadline() (deadline time.Time, ok bool)

func (*RenderContext) Done added in v1.23.0

func (ctx *RenderContext) Done() <-chan struct{}

func (*RenderContext) Err added in v1.23.0

func (ctx *RenderContext) Err() error

func (*RenderContext) ResolveLinkApp added in v1.23.0

func (ctx *RenderContext) ResolveLinkApp(link string) string

func (*RenderContext) ResolveLinkRelative added in v1.23.0

func (ctx *RenderContext) ResolveLinkRelative(base, cur, link string) (finalLink string)

func (*RenderContext) Value added in v1.23.0

func (ctx *RenderContext) Value(key any) any

func (*RenderContext) WithHelper added in v1.23.0

func (ctx *RenderContext) WithHelper(helper RenderHelper) *RenderContext

func (*RenderContext) WithInStandalonePage added in v1.23.0

func (ctx *RenderContext) WithInStandalonePage(v bool) *RenderContext

func (*RenderContext) WithMarkupType added in v1.23.0

func (ctx *RenderContext) WithMarkupType(typ string) *RenderContext

func (*RenderContext) WithMetas added in v1.23.0

func (ctx *RenderContext) WithMetas(metas map[string]string) *RenderContext

func (*RenderContext) WithRelativePath added in v1.23.0

func (ctx *RenderContext) WithRelativePath(path string) *RenderContext
func (ctx *RenderContext) WithUseAbsoluteLink(v bool) *RenderContext

type RenderHelper added in v1.23.0

type RenderHelper interface {
	CleanUp()

	IsCommitIDExisting(commitID string) bool
	ResolveLink(link string, likeType LinkType) string
}

type RenderHelperFuncs added in v1.23.0

type RenderHelperFuncs struct {
	IsUsernameMentionable     func(ctx context.Context, username string) bool
	RenderRepoFileCodePreview func(ctx context.Context, options RenderCodePreviewOptions) (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 added in v1.20.0

type RenderMetaMode string
const (
	RenderMetaAsDetails RenderMetaMode = "details" // default
	RenderMetaAsNone    RenderMetaMode = "none"
	RenderMetaAsTable   RenderMetaMode = "table"
)

type RenderOptions added in v1.23.0

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&regexp (for external issue pattern), teams&org (for mention)
	// BranchNameSubURL (for iframe&asciicast)
	// markupAllowShortIssuePattern
	// markdownLineBreakStyle (comment, document)
	Metas map[string]string

	// used by external render. the router "/org/repo/render/..." will output the rendered content in a standalone page
	InStandalonePage bool
}

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

func GetRendererByFileName(filename string) Renderer

GetRendererByFileName get renderer by filename

type RendererContentDetector added in v1.17.0

type RendererContentDetector interface {
	CanRender(filename string, input io.Reader) bool
}

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

type SimpleRenderHelper added in v1.23.0

type SimpleRenderHelper struct{}

func (*SimpleRenderHelper) CleanUp added in v1.23.0

func (r *SimpleRenderHelper) CleanUp()

func (*SimpleRenderHelper) IsCommitIDExisting added in v1.23.0

func (r *SimpleRenderHelper) IsCommitIDExisting(commitID string) bool
func (r *SimpleRenderHelper) ResolveLink(link string, likeType LinkType) string

type TestRenderHelper added in v1.23.0

type TestRenderHelper struct {
	BaseLink string
	// contains filtered or unexported fields
}

func (*TestRenderHelper) CleanUp added in v1.23.0

func (r *TestRenderHelper) CleanUp()

func (*TestRenderHelper) IsCommitIDExisting added in v1.23.0

func (r *TestRenderHelper) IsCommitIDExisting(commitID string) bool
func (r *TestRenderHelper) ResolveLink(link string, likeType LinkType) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL