Documentation ¶
Index ¶
- Constants
- Variables
- func FindAllMentions(content string) []string
- func IsIPythonNotebook(name string) bool
- func IsMarkdownFile(name string) bool
- func IsOrgModeFile(name string) bool
- func IsReadmeFile(name string) bool
- func Markdown(input interface{}, urlPrefix string, metas map[string]string) []byte
- func NewSanitizer()
- func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte
- func RawMarkdown(body []byte, urlPrefix string) []byte
- func RawOrgMode(body []byte, urlPrefix string) (result []byte)
- func Render(typ Type, input interface{}, urlPrefix string, metas map[string]string) []byte
- func RenderCrossReferenceIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte
- func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
- func Sanitize(s string) string
- func SanitizeBytes(b []byte) []byte
- type MarkdownRenderer
- type Sanitizer
- type Type
Constants ¶
const ( ISSUE_NAME_STYLE_NUMERIC = "numeric" ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric" )
Variables ¶
var ( // MentionPattern matches string that mentions someone, e.g. @Unknwon MentionPattern = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`) // CommitPattern matches link to certain commit with or without trailing hash, // e.g. https://try.gogs.io/gogs/gogs/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2 CommitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`) // IssueFullPattern matches link to an issue with or without trailing hash, // e.g. https://try.gogs.io/gogs/gogs/issues/4#issue-685 IssueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`) // IssueNumericPattern matches string that references to a numeric issue, e.g. #1287 IssueNumericPattern = regexp.MustCompile(`( |^|\()#[0-9]+\b`) // IssueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234 IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`) // CrossReferenceIssueNumericPattern matches string that references a numeric issue in a difference repository // e.g. gogits/gogs#12345 CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+\b`) // Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae // FIXME: this pattern matches pure numbers as well, right now we do a hack to check in RenderSha1CurrentPattern // by converting string to a number. Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`) )
Functions ¶
func FindAllMentions ¶
FindAllMentions matches mention patterns in given content and returns a list of found user names without @ prefix.
func IsIPythonNotebook ¶ added in v0.11.19
IsIPythonNotebook reports whether name looks like a IPython notebook based on its extension.
func IsMarkdownFile ¶
IsMarkdownFile reports whether name looks like a Markdown file based on its extension.
func IsOrgModeFile ¶ added in v0.11.19
IsOrgModeFile reports whether name looks like a Org-mode file based on its extension.
func IsReadmeFile ¶
IsReadmeFile reports whether name looks like a README file based on its extension.
func Markdown ¶
Markdown takes a string or []byte and renders to HTML in Markdown syntax with special links.
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 OrgMode ¶ added in v0.11.19
OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links.
func RawMarkdown ¶
RawMarkdown renders content in Markdown syntax to HTML without handling special links.
func RawOrgMode ¶ added in v0.11.19
RawOrgMode renders content in Org-mode syntax to HTML without handling special links.
func Render ¶
Render takes a string or []byte and renders to HTML in given type of syntax with special links.
func RenderCrossReferenceIssueIndexPattern ¶
func RenderCrossReferenceIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte
RenderCrossReferenceIssueIndexPattern renders issue indexes from other repositories to corresponding links.
func RenderIssueIndexPattern ¶
RenderIssueIndexPattern renders issue indexes to corresponding links.
func RenderSha1CurrentPattern ¶
RenderSha1CurrentPattern renders SHA1 strings to corresponding links that assumes in the same repository.
func RenderSpecialLink ¶
RenderSpecialLink renders mentions, indexes and SHA1 strings to corresponding links.
func Sanitize ¶
Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.
func SanitizeBytes ¶
SanitizeBytes takes a []byte slice that contains a HTML fragment or document and applies policy whitelist.
Types ¶
type MarkdownRenderer ¶
type MarkdownRenderer struct { blackfriday.Renderer // contains filtered or unexported fields }
MarkdownRenderer is a extended version of underlying Markdown render object.
func (*MarkdownRenderer) AutoLink ¶
func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int)
AutoLink defines how auto-detected links should be processed to produce corresponding HTML elements. Reference for kind: https://github.com/russross/blackfriday/blob/master/markdown.go#L69-L76