markup

package
Version: v1.16.8 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 24 Imported by: 402

Documentation

Index

Constants

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

Issue name styles

Variables

View Source
var (

	// EmojiShortCodeRegex find emoji by alias like :smile:
	EmojiShortCodeRegex = regexp.MustCompile(`:[-+\w]+:`)
)

Functions

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

func Init()

Init initialize regexps for markdown parsing

func InitializeSanitizer added in v1.15.0

func InitializeSanitizer()

InitializeSanitizer (re)initializes the current sanitizer to account for changes in settings

func IsLink(link []byte) bool

IsLink reports whether link fits valid format.

func IsMarkupFile added in v1.3.0

func IsMarkupFile(name, markup string) bool

IsMarkupFile reports whether file is a markup type file

func IsReadmeFile

func IsReadmeFile(name string, ext ...string) bool

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

func IsSameDomain(s string) bool

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(
	ctx *RenderContext,
	input io.Reader,
	output io.Writer,
) 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 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 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(
	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 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 SanitizeReader added in v1.11.0

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

SanitizeReader sanitizes a Reader

func Type

func Type(filename string) string

Type returns if markup format via the filename

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

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

type RenderContext struct {
	Ctx           context.Context
	Filename      string
	Type          string
	IsWiki        bool
	URLPrefix     string
	Metas         map[string]string
	DefaultLink   string
	GitRepo       *git.Repository
	ShaExistCache map[string]bool
	// 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 Renderer added in v1.15.0

type Renderer interface {
	Name() string // markup format name
	Extensions() []string
	NeedPostProcess() bool
	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

func GetRendererByType added in v1.15.0

func GetRendererByType(tp string) Renderer

GetRendererByType returns a renderer according type

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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