4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-09-18 06:02:30 +00:00

Update dependencies and go1.18 (#1873)

* Update dependencies and go1.18

* Exclude unnecessary linters and update build to go1.18
This commit is contained in:
Wim
2022-08-13 16:14:26 +02:00
committed by GitHub
parent 3c4192ebf6
commit 6a3fc71397
396 changed files with 350176 additions and 309792 deletions

View File

@@ -2,9 +2,11 @@
[![pkg.go.dev](https://pkg.go.dev/badge/github.com/gomarkdown/markdown)](https://pkg.go.dev/github.com/gomarkdown/markdown)
Package `github.com/gomarkdown/markdown` is a very fast Go library for parsing [Markdown](https://daringfireball.net/projects/markdown/) documents and rendering them to HTML.
Package `github.com/gomarkdown/markdown` is a Go library for parsing Markdown text and rendering as HTML.
It's fast and supports common extensions.
It's very fast and supports common extensions.
Try code examples online: https://replit.com/@kjk1?path=folder/gomarkdown
## API Docs:
@@ -15,17 +17,7 @@ It's fast and supports common extensions.
## Users
Some tools using this package:
- https://github.com/MichaelMure/go-term-markdown : markdown renderer for the terminal
- https://github.com/artyom/mdserver : web server that serves markdown files
- https://github.com/rsdoiel/mkpage : content management system generating static websites
- https://github.com/cugu/dashboard : creates a badge dashboard from a yaml file
- https://github.com/ieyasu/go-bwiki : simple wiki
- https://github.com/romanyx/mdopen : view markdown files in the default browser
- https://github.com/ystyle/sqlmanager : a library for manager sql with markdown like beetsql
- https://gitlab.com/kendellfab/fazer : library for making templates
- https://github.com/blmayer/tasker : a simple task list web app
Some tools using this package: https://pkg.go.dev/github.com/gomarkdown/markdown?tab=importedby
## Usage
@@ -36,6 +28,8 @@ md := []byte("## markdown document")
output := markdown.ToHTML(md, nil, nil)
```
Try it online: https://replit.com/@kjk1/gomarkdown-basic
## Customizing markdown parser
Markdown format is loosely specified and there are multiple extensions invented after original specification was created.
@@ -57,6 +51,8 @@ md := []byte("markdown text")
html := markdown.ToHTML(md, parser, nil)
```
Try it online: https://replit.com/@kjk1/gomarkdown-customized-html-renderer
## Customizing HTML renderer
Similarly, HTML renderer can be configured with different [options](https://pkg.go.dev/github.com/gomarkdown/markdown/html#RendererOptions)
@@ -77,6 +73,8 @@ md := []byte("markdown text")
html := markdown.ToHTML(md, nil, renderer)
```
Try it online: https://replit.com/@kjk1/gomarkdown-customized-html-renderer
HTML renderer also supports reusing most of the logic and overriding rendering of only specific nodes.
You can provide [RenderNodeFunc](https://pkg.go.dev/github.com/gomarkdown/markdown/html#RenderNodeFunc) in [RendererOptions](https://pkg.go.dev/github.com/gomarkdown/markdown/html#RendererOptions).

View File

@@ -133,6 +133,9 @@ type Renderer struct {
// if > 0, will strip html tags in Out and Outs
DisableTags int
// TODO: documentation
IsSafeURLOverride func(url []byte) bool
sr *SPRenderer
documentMatter ast.DocumentMatters // keep track of front/main/back matter.
@@ -281,11 +284,16 @@ func isMailto(link []byte) bool {
return bytes.HasPrefix(link, []byte("mailto:"))
}
func needSkipLink(flags Flags, dest []byte) bool {
func needSkipLink(r *Renderer, dest []byte) bool {
flags := r.opts.Flags
if flags&SkipLinks != 0 {
return true
}
return flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest)
isSafeURL := r.IsSafeURLOverride
if isSafeURL == nil {
isSafeURL = valid.IsSafeURL
}
return flags&Safelink != 0 && !isSafeURL(dest) && !isMailto(dest)
}
func appendLanguageAttr(attrs []string, info []byte) []string {
@@ -481,7 +489,7 @@ func (r *Renderer) linkExit(w io.Writer, link *ast.Link) {
// Link writes ast.Link node
func (r *Renderer) Link(w io.Writer, link *ast.Link, entering bool) {
// mark it but don't link it if it is not a safe link: no smartypants
if needSkipLink(r.opts.Flags, link.Destination) {
if needSkipLink(r, link.Destination) {
r.OutOneOf(w, entering, "<tt>", "</tt>")
return
}
@@ -1226,28 +1234,6 @@ func isListItemTerm(node ast.Node) bool {
return ok && data.ListFlags&ast.ListTypeTerm != 0
}
func isSafeLink(link []byte) bool {
for _, path := range valid.Paths {
if len(link) >= len(path) && bytes.Equal(link[:len(path)], path) {
if len(link) == len(path) {
return true
} else if isAlnum(link[len(path)]) {
return true
}
}
}
for _, prefix := range valid.URIs {
// TODO: handle unicode here
// case-insensitive prefix test
if len(link) > len(prefix) && bytes.Equal(bytes.ToLower(link[:len(prefix)]), prefix) && isAlnum(link[len(prefix)]) {
return true
}
}
return false
}
// TODO: move to internal package
// Create a url-safe slug for fragments
func slugify(in []byte) []byte {

View File

@@ -1,5 +1,9 @@
package valid
import (
"bytes"
)
var URIs = [][]byte{
[]byte("http://"),
[]byte("https://"),
@@ -12,3 +16,44 @@ var Paths = [][]byte{
[]byte("./"),
[]byte("../"),
}
// TODO: documentation
func IsSafeURL(url []byte) bool {
nLink := len(url)
for _, path := range Paths {
nPath := len(path)
linkPrefix := url[:nPath]
if nLink >= nPath && bytes.Equal(linkPrefix, path) {
if nLink == nPath {
return true
} else if isAlnum(url[nPath]) {
return true
}
}
}
for _, prefix := range URIs {
// TODO: handle unicode here
// case-insensitive prefix test
nPrefix := len(prefix)
if nLink > nPrefix {
linkPrefix := bytes.ToLower(url[:nPrefix])
if bytes.Equal(linkPrefix, prefix) && isAlnum(url[nPrefix]) {
return true
}
}
}
return false
}
// isAlnum returns true if c is a digit or letter
// TODO: check when this is looking for ASCII alnum and when it should use unicode
func isAlnum(c byte) bool {
return (c >= '0' && c <= '9') || isLetter(c)
}
// isLetter returns true if c is ascii letter
func isLetter(c byte) bool {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
}

View File

@@ -899,7 +899,11 @@ func autoLink(p *Parser, data []byte, offset int) (int, ast.Node) {
origData := data
data = data[offset-rewind:]
if !isSafeLink(data) {
isSafeURL := p.IsSafeURLOverride
if isSafeURL == nil {
isSafeURL = valid.IsSafeURL
}
if !isSafeURL(data) {
return 0, nil
}
@@ -995,35 +999,6 @@ func isEndOfLink(char byte) bool {
return isSpace(char) || char == '<'
}
func isSafeLink(link []byte) bool {
nLink := len(link)
for _, path := range valid.Paths {
nPath := len(path)
linkPrefix := link[:nPath]
if nLink >= nPath && bytes.Equal(linkPrefix, path) {
if nLink == nPath {
return true
} else if isAlnum(link[nPath]) {
return true
}
}
}
for _, prefix := range valid.URIs {
// TODO: handle unicode here
// case-insensitive prefix test
nPrefix := len(prefix)
if nLink > nPrefix {
linkPrefix := bytes.ToLower(link[:nPrefix])
if bytes.Equal(linkPrefix, prefix) && isAlnum(link[nPrefix]) {
return true
}
}
}
return false
}
// return the length of the given tag, or 0 is it's not valid
func tagLength(data []byte) (autolink autolinkType, end int) {
var i, j int

View File

@@ -84,6 +84,9 @@ type Parser struct {
// the bottom will be used to fill in the link details.
ReferenceOverride ReferenceOverrideFunc
// TODO: documentation
IsSafeURLOverride func(url []byte) bool
Opts Options
// after parsing, this is AST root of parsed markdown text