[chore]: Bump github.com/yuin/goldmark from 1.5.5 to 1.5.6 (#2140)
This commit is contained in:
parent
1e2db7a32f
commit
36dceac56c
2
go.mod
2
go.mod
|
@ -52,7 +52,7 @@ require (
|
||||||
github.com/uptrace/bun/dialect/sqlitedialect v1.1.14
|
github.com/uptrace/bun/dialect/sqlitedialect v1.1.14
|
||||||
github.com/uptrace/bun/extra/bunotel v1.1.14
|
github.com/uptrace/bun/extra/bunotel v1.1.14
|
||||||
github.com/wagslane/go-password-validator v0.3.0
|
github.com/wagslane/go-password-validator v0.3.0
|
||||||
github.com/yuin/goldmark v1.5.5
|
github.com/yuin/goldmark v1.5.6
|
||||||
go.opentelemetry.io/otel v1.16.0
|
go.opentelemetry.io/otel v1.16.0
|
||||||
go.opentelemetry.io/otel/exporters/jaeger v1.16.0
|
go.opentelemetry.io/otel/exporters/jaeger v1.16.0
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -635,8 +635,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
||||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
github.com/yuin/goldmark v1.5.5 h1:IJznPe8wOzfIKETmMkd06F8nXkmlhaHqFRM9l1hAGsU=
|
github.com/yuin/goldmark v1.5.6 h1:COmQAWTCcGetChm3Ig7G/t8AFAN00t+o8Mt4cf7JpwA=
|
||||||
github.com/yuin/goldmark v1.5.5/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.5.6/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
||||||
github.com/zeebo/blake3 v0.2.1/go.mod h1:TSQ0KjMH+pht+bRyvVooJ1rBpvvngSGaPISafq9MxJk=
|
github.com/zeebo/blake3 v0.2.1/go.mod h1:TSQ0KjMH+pht+bRyvVooJ1rBpvvngSGaPISafq9MxJk=
|
||||||
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
|
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
run:
|
||||||
|
deadline: 10m
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-use-default: false
|
||||||
|
exclude-rules:
|
||||||
|
- path: _test.go
|
||||||
|
linters:
|
||||||
|
- errcheck
|
||||||
|
- lll
|
||||||
|
exclude:
|
||||||
|
- "Package util"
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- errcheck
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- typecheck
|
||||||
|
- unused
|
||||||
|
- gofmt
|
||||||
|
- godot
|
||||||
|
- makezero
|
||||||
|
- misspell
|
||||||
|
- revive
|
||||||
|
- wastedassign
|
||||||
|
- lll
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
revive:
|
||||||
|
severity: "warning"
|
||||||
|
confidence: 0.8
|
||||||
|
rules:
|
||||||
|
- name: blank-imports
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: context-as-argument
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: context-keys-type
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: dot-imports
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: error-return
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: error-strings
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: error-naming
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: exported
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: increment-decrement
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: var-naming
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: var-declaration
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: package-comments
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: range
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: receiver-naming
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: time-naming
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: unexported-return
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: indent-error-flow
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: errorf
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: empty-block
|
||||||
|
severity: warning
|
||||||
|
disabled: true
|
||||||
|
- name: superfluous-else
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: unused-parameter
|
||||||
|
severity: warning
|
||||||
|
disabled: true
|
||||||
|
- name: unreachable-code
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: redefines-builtin-id
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
|
@ -1,4 +1,7 @@
|
||||||
.PHONY: test fuzz
|
.PHONY: test fuzz lint
|
||||||
|
|
||||||
|
lint:
|
||||||
|
golangci-lint run -c .golangci.yml ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -coverprofile=profile.out -coverpkg=github.com/yuin/goldmark,github.com/yuin/goldmark/ast,github.com/yuin/goldmark/extension,github.com/yuin/goldmark/extension/ast,github.com/yuin/goldmark/parser,github.com/yuin/goldmark/renderer,github.com/yuin/goldmark/renderer/html,github.com/yuin/goldmark/text,github.com/yuin/goldmark/util ./...
|
go test -coverprofile=profile.out -coverpkg=github.com/yuin/goldmark,github.com/yuin/goldmark/ast,github.com/yuin/goldmark/extension,github.com/yuin/goldmark/extension/ast,github.com/yuin/goldmark/parser,github.com/yuin/goldmark/renderer,github.com/yuin/goldmark/renderer/html,github.com/yuin/goldmark/text,github.com/yuin/goldmark/util ./...
|
||||||
|
|
|
@ -39,7 +39,7 @@ func NewNodeKind(name string) NodeKind {
|
||||||
return kindMax
|
return kindMax
|
||||||
}
|
}
|
||||||
|
|
||||||
// An Attribute is an attribute of the Node
|
// An Attribute is an attribute of the Node.
|
||||||
type Attribute struct {
|
type Attribute struct {
|
||||||
Name []byte
|
Name []byte
|
||||||
Value interface{}
|
Value interface{}
|
||||||
|
@ -248,7 +248,7 @@ func (n *BaseNode) RemoveChildren(self Node) {
|
||||||
n.childCount = 0
|
n.childCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// SortChildren implements Node.SortChildren
|
// SortChildren implements Node.SortChildren.
|
||||||
func (n *BaseNode) SortChildren(comparator func(n1, n2 Node) int) {
|
func (n *BaseNode) SortChildren(comparator func(n1, n2 Node) int) {
|
||||||
var sorted Node
|
var sorted Node
|
||||||
current := n.firstChild
|
current := n.firstChild
|
||||||
|
@ -358,7 +358,7 @@ func (n *BaseNode) InsertBefore(self, v1, insertee Node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OwnerDocument implements Node.OwnerDocument
|
// OwnerDocument implements Node.OwnerDocument.
|
||||||
func (n *BaseNode) OwnerDocument() *Document {
|
func (n *BaseNode) OwnerDocument() *Document {
|
||||||
d := n.Parent()
|
d := n.Parent()
|
||||||
for {
|
for {
|
||||||
|
@ -399,7 +399,7 @@ func (n *BaseNode) SetAttribute(name []byte, value interface{}) {
|
||||||
n.attributes = append(n.attributes, Attribute{name, value})
|
n.attributes = append(n.attributes, Attribute{name, value})
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAttributeString implements Node.SetAttributeString
|
// SetAttributeString implements Node.SetAttributeString.
|
||||||
func (n *BaseNode) SetAttributeString(name string, value interface{}) {
|
func (n *BaseNode) SetAttributeString(name string, value interface{}) {
|
||||||
n.SetAttribute(util.StringToReadOnlyBytes(name), value)
|
n.SetAttribute(util.StringToReadOnlyBytes(name), value)
|
||||||
}
|
}
|
||||||
|
@ -422,12 +422,12 @@ func (n *BaseNode) AttributeString(s string) (interface{}, bool) {
|
||||||
return n.Attribute(util.StringToReadOnlyBytes(s))
|
return n.Attribute(util.StringToReadOnlyBytes(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attributes implements Node.Attributes
|
// Attributes implements Node.Attributes.
|
||||||
func (n *BaseNode) Attributes() []Attribute {
|
func (n *BaseNode) Attributes() []Attribute {
|
||||||
return n.attributes
|
return n.attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveAttributes implements Node.RemoveAttributes
|
// RemoveAttributes implements Node.RemoveAttributes.
|
||||||
func (n *BaseNode) RemoveAttributes() {
|
func (n *BaseNode) RemoveAttributes() {
|
||||||
n.attributes = nil
|
n.attributes = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,12 @@ type BaseBlock struct {
|
||||||
lines *textm.Segments
|
lines *textm.Segments
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type implements Node.Type
|
// Type implements Node.Type.
|
||||||
func (b *BaseBlock) Type() NodeType {
|
func (b *BaseBlock) Type() NodeType {
|
||||||
return TypeBlock
|
return TypeBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRaw implements Node.IsRaw
|
// IsRaw implements Node.IsRaw.
|
||||||
func (b *BaseBlock) IsRaw() bool {
|
func (b *BaseBlock) IsRaw() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func (b *BaseBlock) SetBlankPreviousLines(v bool) {
|
||||||
b.blankPreviousLines = v
|
b.blankPreviousLines = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lines implements Node.Lines
|
// Lines implements Node.Lines.
|
||||||
func (b *BaseBlock) Lines() *textm.Segments {
|
func (b *BaseBlock) Lines() *textm.Segments {
|
||||||
if b.lines == nil {
|
if b.lines == nil {
|
||||||
b.lines = textm.NewSegments()
|
b.lines = textm.NewSegments()
|
||||||
|
@ -42,7 +42,7 @@ func (b *BaseBlock) Lines() *textm.Segments {
|
||||||
return b.lines
|
return b.lines
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLines implements Node.SetLines
|
// SetLines implements Node.SetLines.
|
||||||
func (b *BaseBlock) SetLines(v *textm.Segments) {
|
func (b *BaseBlock) SetLines(v *textm.Segments) {
|
||||||
b.lines = v
|
b.lines = v
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func (n *Document) Kind() NodeKind {
|
||||||
return KindDocument
|
return KindDocument
|
||||||
}
|
}
|
||||||
|
|
||||||
// OwnerDocument implements Node.OwnerDocument
|
// OwnerDocument implements Node.OwnerDocument.
|
||||||
func (n *Document) OwnerDocument() *Document {
|
func (n *Document) OwnerDocument() *Document {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
@ -431,19 +431,19 @@ func NewListItem(offset int) *ListItem {
|
||||||
type HTMLBlockType int
|
type HTMLBlockType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// HTMLBlockType1 represents type 1 html blocks
|
// HTMLBlockType1 represents type 1 html blocks.
|
||||||
HTMLBlockType1 HTMLBlockType = iota + 1
|
HTMLBlockType1 HTMLBlockType = iota + 1
|
||||||
// HTMLBlockType2 represents type 2 html blocks
|
// HTMLBlockType2 represents type 2 html blocks.
|
||||||
HTMLBlockType2
|
HTMLBlockType2
|
||||||
// HTMLBlockType3 represents type 3 html blocks
|
// HTMLBlockType3 represents type 3 html blocks.
|
||||||
HTMLBlockType3
|
HTMLBlockType3
|
||||||
// HTMLBlockType4 represents type 4 html blocks
|
// HTMLBlockType4 represents type 4 html blocks.
|
||||||
HTMLBlockType4
|
HTMLBlockType4
|
||||||
// HTMLBlockType5 represents type 5 html blocks
|
// HTMLBlockType5 represents type 5 html blocks.
|
||||||
HTMLBlockType5
|
HTMLBlockType5
|
||||||
// HTMLBlockType6 represents type 6 html blocks
|
// HTMLBlockType6 represents type 6 html blocks.
|
||||||
HTMLBlockType6
|
HTMLBlockType6
|
||||||
// HTMLBlockType7 represents type 7 html blocks
|
// HTMLBlockType7 represents type 7 html blocks.
|
||||||
HTMLBlockType7
|
HTMLBlockType7
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,12 @@ type BaseInline struct {
|
||||||
BaseNode
|
BaseNode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type implements Node.Type
|
// Type implements Node.Type.
|
||||||
func (b *BaseInline) Type() NodeType {
|
func (b *BaseInline) Type() NodeType {
|
||||||
return TypeInline
|
return TypeInline
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRaw implements Node.IsRaw
|
// IsRaw implements Node.IsRaw.
|
||||||
func (b *BaseInline) IsRaw() bool {
|
func (b *BaseInline) IsRaw() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ func (b *BaseInline) SetBlankPreviousLines(v bool) {
|
||||||
panic("can not call with inline nodes.")
|
panic("can not call with inline nodes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lines implements Node.Lines
|
// Lines implements Node.Lines.
|
||||||
func (b *BaseInline) Lines() *textm.Segments {
|
func (b *BaseInline) Lines() *textm.Segments {
|
||||||
panic("can not call with inline nodes.")
|
panic("can not call with inline nodes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLines implements Node.SetLines
|
// SetLines implements Node.SetLines.
|
||||||
func (b *BaseInline) SetLines(v *textm.Segments) {
|
func (b *BaseInline) SetLines(v *textm.Segments) {
|
||||||
panic("can not call with inline nodes.")
|
panic("can not call with inline nodes.")
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,8 @@ func (n *Text) Merge(node Node, source []byte) bool {
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if n.Segment.Stop != t.Segment.Start || t.Segment.Padding != 0 || source[n.Segment.Stop-1] == '\n' || t.IsRaw() != n.IsRaw() {
|
if n.Segment.Stop != t.Segment.Start || t.Segment.Padding != 0 ||
|
||||||
|
source[n.Segment.Stop-1] == '\n' || t.IsRaw() != n.IsRaw() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n.Segment.Stop = t.Segment.Stop
|
n.Segment.Stop = t.Segment.Stop
|
||||||
|
@ -214,7 +215,7 @@ func MergeOrReplaceTextSegment(parent Node, n Node, s textm.Segment) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A String struct is a textual content that has a concrete value
|
// A String struct is a textual content that has a concrete value.
|
||||||
type String struct {
|
type String struct {
|
||||||
BaseInline
|
BaseInline
|
||||||
|
|
||||||
|
@ -305,7 +306,7 @@ func (n *CodeSpan) IsBlank(source []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump implements Node.Dump
|
// Dump implements Node.Dump.
|
||||||
func (n *CodeSpan) Dump(source []byte, level int) {
|
func (n *CodeSpan) Dump(source []byte, level int) {
|
||||||
DumpHelper(n, source, level, nil, nil)
|
DumpHelper(n, source, level, nil, nil)
|
||||||
}
|
}
|
||||||
|
@ -467,7 +468,7 @@ type AutoLink struct {
|
||||||
// Inline implements Inline.Inline.
|
// Inline implements Inline.Inline.
|
||||||
func (n *AutoLink) Inline() {}
|
func (n *AutoLink) Inline() {}
|
||||||
|
|
||||||
// Dump implements Node.Dump
|
// Dump implements Node.Dump.
|
||||||
func (n *AutoLink) Dump(source []byte, level int) {
|
func (n *AutoLink) Dump(source []byte, level int) {
|
||||||
segment := n.value.Segment
|
segment := n.value.Segment
|
||||||
m := map[string]string{
|
m := map[string]string{
|
||||||
|
|
|
@ -88,7 +88,7 @@ type Footnote struct {
|
||||||
func (n *Footnote) Dump(source []byte, level int) {
|
func (n *Footnote) Dump(source []byte, level int) {
|
||||||
m := map[string]string{}
|
m := map[string]string{}
|
||||||
m["Index"] = fmt.Sprintf("%v", n.Index)
|
m["Index"] = fmt.Sprintf("%v", n.Index)
|
||||||
m["Ref"] = fmt.Sprintf("%s", n.Ref)
|
m["Ref"] = string(n.Ref)
|
||||||
gast.DumpHelper(n, source, level, m, nil)
|
gast.DumpHelper(n, source, level, m, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,9 @@ package ast
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
gast "github.com/yuin/goldmark/ast"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
gast "github.com/yuin/goldmark/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Alignment is a text alignment of table cells.
|
// Alignment is a text alignment of table cells.
|
||||||
|
@ -45,7 +46,7 @@ type Table struct {
|
||||||
Alignments []Alignment
|
Alignments []Alignment
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump implements Node.Dump
|
// Dump implements Node.Dump.
|
||||||
func (n *Table) Dump(source []byte, level int) {
|
func (n *Table) Dump(source []byte, level int) {
|
||||||
gast.DumpHelper(n, source, level, nil, func(level int) {
|
gast.DumpHelper(n, source, level, nil, func(level int) {
|
||||||
indent := strings.Repeat(" ", level)
|
indent := strings.Repeat(" ", level)
|
||||||
|
|
|
@ -29,6 +29,7 @@ type cjk struct {
|
||||||
EscapedSpace bool
|
EscapedSpace bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CJK is a goldmark extension that provides functionalities for CJK languages.
|
||||||
var CJK = NewCJK(WithEastAsianLineBreaks(), WithEscapedSpace())
|
var CJK = NewCJK(WithEastAsianLineBreaks(), WithEscapedSpace())
|
||||||
|
|
||||||
// NewCJK returns a new extension with given options.
|
// NewCJK returns a new extension with given options.
|
||||||
|
|
|
@ -113,7 +113,8 @@ func (b *definitionDescriptionParser) Trigger() []byte {
|
||||||
return []byte{':'}
|
return []byte{':'}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *definitionDescriptionParser) Open(parent gast.Node, reader text.Reader, pc parser.Context) (gast.Node, parser.State) {
|
func (b *definitionDescriptionParser) Open(
|
||||||
|
parent gast.Node, reader text.Reader, pc parser.Context) (gast.Node, parser.State) {
|
||||||
line, _ := reader.PeekLine()
|
line, _ := reader.PeekLine()
|
||||||
pos := pc.BlockOffset()
|
pos := pc.BlockOffset()
|
||||||
indent := pc.BlockIndent()
|
indent := pc.BlockIndent()
|
||||||
|
@ -199,7 +200,8 @@ func (r *DefinitionListHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFunc
|
||||||
// DefinitionListAttributeFilter defines attribute names which dl elements can have.
|
// DefinitionListAttributeFilter defines attribute names which dl elements can have.
|
||||||
var DefinitionListAttributeFilter = html.GlobalAttributeFilter
|
var DefinitionListAttributeFilter = html.GlobalAttributeFilter
|
||||||
|
|
||||||
func (r *DefinitionListHTMLRenderer) renderDefinitionList(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *DefinitionListHTMLRenderer) renderDefinitionList(
|
||||||
|
w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
_, _ = w.WriteString("<dl")
|
_, _ = w.WriteString("<dl")
|
||||||
|
@ -217,7 +219,8 @@ func (r *DefinitionListHTMLRenderer) renderDefinitionList(w util.BufWriter, sour
|
||||||
// DefinitionTermAttributeFilter defines attribute names which dd elements can have.
|
// DefinitionTermAttributeFilter defines attribute names which dd elements can have.
|
||||||
var DefinitionTermAttributeFilter = html.GlobalAttributeFilter
|
var DefinitionTermAttributeFilter = html.GlobalAttributeFilter
|
||||||
|
|
||||||
func (r *DefinitionListHTMLRenderer) renderDefinitionTerm(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *DefinitionListHTMLRenderer) renderDefinitionTerm(
|
||||||
|
w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
_, _ = w.WriteString("<dt")
|
_, _ = w.WriteString("<dt")
|
||||||
|
@ -235,7 +238,8 @@ func (r *DefinitionListHTMLRenderer) renderDefinitionTerm(w util.BufWriter, sour
|
||||||
// DefinitionDescriptionAttributeFilter defines attribute names which dd elements can have.
|
// DefinitionDescriptionAttributeFilter defines attribute names which dd elements can have.
|
||||||
var DefinitionDescriptionAttributeFilter = html.GlobalAttributeFilter
|
var DefinitionDescriptionAttributeFilter = html.GlobalAttributeFilter
|
||||||
|
|
||||||
func (r *DefinitionListHTMLRenderer) renderDefinitionDescription(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *DefinitionListHTMLRenderer) renderDefinitionDescription(
|
||||||
|
w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
n := node.(*ast.DefinitionDescription)
|
n := node.(*ast.DefinitionDescription)
|
||||||
_, _ = w.WriteString("<dd")
|
_, _ = w.WriteString("<dd")
|
||||||
|
|
|
@ -44,8 +44,8 @@ func (b *footnoteBlockParser) Open(parent gast.Node, reader text.Reader, pc pars
|
||||||
return nil, parser.NoChildren
|
return nil, parser.NoChildren
|
||||||
}
|
}
|
||||||
open := pos + 1
|
open := pos + 1
|
||||||
closes := 0
|
var closes int
|
||||||
closure := util.FindClosure(line[pos+1:], '[', ']', false, false)
|
closure := util.FindClosure(line[pos+1:], '[', ']', false, false) //nolint:staticcheck
|
||||||
closes = pos + 1 + closure
|
closes = pos + 1 + closure
|
||||||
next := closes + 1
|
next := closes + 1
|
||||||
if closure > -1 {
|
if closure > -1 {
|
||||||
|
@ -136,7 +136,7 @@ func (s *footnoteParser) Parse(parent gast.Node, block text.Reader, pc parser.Co
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
open := pos
|
open := pos
|
||||||
closure := util.FindClosure(line[pos:], '[', ']', false, false)
|
closure := util.FindClosure(line[pos:], '[', ']', false, false) //nolint:staticcheck
|
||||||
if closure < 0 {
|
if closure < 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ func (s *footnoteParser) Parse(parent gast.Node, block text.Reader, pc parser.Co
|
||||||
d := def.(*ast.Footnote)
|
d := def.(*ast.Footnote)
|
||||||
if bytes.Equal(d.Ref, value) {
|
if bytes.Equal(d.Ref, value) {
|
||||||
if d.Index < 0 {
|
if d.Index < 0 {
|
||||||
list.Count += 1
|
list.Count++
|
||||||
d.Index = list.Count
|
d.Index = list.Count
|
||||||
}
|
}
|
||||||
index = d.Index
|
index = d.Index
|
||||||
|
@ -272,9 +272,9 @@ func (a *footnoteASTTransformer) Transform(node *gast.Document, reader text.Read
|
||||||
// FootnoteConfig holds configuration values for the footnote extension.
|
// FootnoteConfig holds configuration values for the footnote extension.
|
||||||
//
|
//
|
||||||
// Link* and Backlink* configurations have some variables:
|
// Link* and Backlink* configurations have some variables:
|
||||||
// Occurrances of “^^” in the string will be replaced by the
|
// Occurrences of “^^” in the string will be replaced by the
|
||||||
// corresponding footnote number in the HTML output.
|
// corresponding footnote number in the HTML output.
|
||||||
// Occurrances of “%%” will be replaced by a number for the
|
// Occurrences of “%%” will be replaced by a number for the
|
||||||
// reference (footnotes can have multiple references).
|
// reference (footnotes can have multiple references).
|
||||||
type FootnoteConfig struct {
|
type FootnoteConfig struct {
|
||||||
html.Config
|
html.Config
|
||||||
|
@ -525,7 +525,8 @@ func (r *FootnoteHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegist
|
||||||
reg.Register(ast.KindFootnoteList, r.renderFootnoteList)
|
reg.Register(ast.KindFootnoteList, r.renderFootnoteList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FootnoteHTMLRenderer) renderFootnoteLink(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *FootnoteHTMLRenderer) renderFootnoteLink(
|
||||||
|
w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
n := node.(*ast.FootnoteLink)
|
n := node.(*ast.FootnoteLink)
|
||||||
is := strconv.Itoa(n.Index)
|
is := strconv.Itoa(n.Index)
|
||||||
|
@ -556,7 +557,8 @@ func (r *FootnoteHTMLRenderer) renderFootnoteLink(w util.BufWriter, source []byt
|
||||||
return gast.WalkContinue, nil
|
return gast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FootnoteHTMLRenderer) renderFootnoteBacklink(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *FootnoteHTMLRenderer) renderFootnoteBacklink(
|
||||||
|
w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
n := node.(*ast.FootnoteBacklink)
|
n := node.(*ast.FootnoteBacklink)
|
||||||
is := strconv.Itoa(n.Index)
|
is := strconv.Itoa(n.Index)
|
||||||
|
@ -581,7 +583,8 @@ func (r *FootnoteHTMLRenderer) renderFootnoteBacklink(w util.BufWriter, source [
|
||||||
return gast.WalkContinue, nil
|
return gast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FootnoteHTMLRenderer) renderFootnote(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *FootnoteHTMLRenderer) renderFootnote(
|
||||||
|
w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
n := node.(*ast.Footnote)
|
n := node.(*ast.Footnote)
|
||||||
is := strconv.Itoa(n.Index)
|
is := strconv.Itoa(n.Index)
|
||||||
if entering {
|
if entering {
|
||||||
|
@ -600,7 +603,8 @@ func (r *FootnoteHTMLRenderer) renderFootnote(w util.BufWriter, source []byte, n
|
||||||
return gast.WalkContinue, nil
|
return gast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FootnoteHTMLRenderer) renderFootnoteList(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *FootnoteHTMLRenderer) renderFootnoteList(
|
||||||
|
w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
_, _ = w.WriteString(`<div class="footnotes" role="doc-endnotes"`)
|
_, _ = w.WriteString(`<div class="footnotes" role="doc-endnotes"`)
|
||||||
if node.Attributes() != nil {
|
if node.Attributes() != nil {
|
||||||
|
|
|
@ -11,9 +11,9 @@ import (
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var wwwURLRegxp = regexp.MustCompile(`^www\.[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]+(?:[/#?][-a-zA-Z0-9@:%_\+.~#!?&/=\(\);,'">\^{}\[\]` + "`" + `]*)?`)
|
var wwwURLRegxp = regexp.MustCompile(`^www\.[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]+(?:[/#?][-a-zA-Z0-9@:%_\+.~#!?&/=\(\);,'">\^{}\[\]` + "`" + `]*)?`) //nolint:golint,lll
|
||||||
|
|
||||||
var urlRegexp = regexp.MustCompile(`^(?:http|https|ftp)://[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]+(?::\d+)?(?:[/#?][-a-zA-Z0-9@:%_+.~#$!?&/=\(\);,'">\^{}\[\]` + "`" + `]*)?`)
|
var urlRegexp = regexp.MustCompile(`^(?:http|https|ftp)://[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]+(?::\d+)?(?:[/#?][-a-zA-Z0-9@:%_+.~#$!?&/=\(\);,'">\^{}\[\]` + "`" + `]*)?`) //nolint:golint,lll
|
||||||
|
|
||||||
// An LinkifyConfig struct is a data structure that holds configuration of the
|
// An LinkifyConfig struct is a data structure that holds configuration of the
|
||||||
// Linkify extension.
|
// Linkify extension.
|
||||||
|
@ -92,9 +92,6 @@ func WithLinkifyURLRegexp(value *regexp.Regexp) LinkifyOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLinkifyWWWRegexp is a functional option that specify
|
|
||||||
// a pattern of the URL without a protocol.
|
|
||||||
// This pattern must start with 'www.' .
|
|
||||||
type withLinkifyWWWRegexp struct {
|
type withLinkifyWWWRegexp struct {
|
||||||
value *regexp.Regexp
|
value *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
@ -107,14 +104,15 @@ func (o *withLinkifyWWWRegexp) SetLinkifyOption(p *LinkifyConfig) {
|
||||||
p.WWWRegexp = o.value
|
p.WWWRegexp = o.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLinkifyWWWRegexp is a functional option that specify
|
||||||
|
// a pattern of the URL without a protocol.
|
||||||
|
// This pattern must start with 'www.' .
|
||||||
func WithLinkifyWWWRegexp(value *regexp.Regexp) LinkifyOption {
|
func WithLinkifyWWWRegexp(value *regexp.Regexp) LinkifyOption {
|
||||||
return &withLinkifyWWWRegexp{
|
return &withLinkifyWWWRegexp{
|
||||||
value: value,
|
value: value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLinkifyWWWRegexp is a functional otpion that specify
|
|
||||||
// a pattern of the email address.
|
|
||||||
type withLinkifyEmailRegexp struct {
|
type withLinkifyEmailRegexp struct {
|
||||||
value *regexp.Regexp
|
value *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
@ -127,6 +125,8 @@ func (o *withLinkifyEmailRegexp) SetLinkifyOption(p *LinkifyConfig) {
|
||||||
p.EmailRegexp = o.value
|
p.EmailRegexp = o.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLinkifyEmailRegexp is a functional otpion that specify
|
||||||
|
// a pattern of the email address.
|
||||||
func WithLinkifyEmailRegexp(value *regexp.Regexp) LinkifyOption {
|
func WithLinkifyEmailRegexp(value *regexp.Regexp) LinkifyOption {
|
||||||
return &withLinkifyEmailRegexp{
|
return &withLinkifyEmailRegexp{
|
||||||
value: value,
|
value: value,
|
||||||
|
@ -303,6 +303,8 @@ type linkify struct {
|
||||||
// Linkify is an extension that allow you to parse text that seems like a URL.
|
// Linkify is an extension that allow you to parse text that seems like a URL.
|
||||||
var Linkify = &linkify{}
|
var Linkify = &linkify{}
|
||||||
|
|
||||||
|
// NewLinkify creates a new [goldmark.Extender] that
|
||||||
|
// allow you to parse text that seems like a URL.
|
||||||
func NewLinkify(opts ...LinkifyOption) goldmark.Extender {
|
func NewLinkify(opts ...LinkifyOption) goldmark.Extender {
|
||||||
return &linkify{
|
return &linkify{
|
||||||
options: opts,
|
options: opts,
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Package extension is a collection of builtin extensions.
|
||||||
|
package extension
|
|
@ -85,7 +85,8 @@ func (r *StrikethroughHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncR
|
||||||
// StrikethroughAttributeFilter defines attribute names which dd elements can have.
|
// StrikethroughAttributeFilter defines attribute names which dd elements can have.
|
||||||
var StrikethroughAttributeFilter = html.GlobalAttributeFilter
|
var StrikethroughAttributeFilter = html.GlobalAttributeFilter
|
||||||
|
|
||||||
func (r *StrikethroughHTMLRenderer) renderStrikethrough(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *StrikethroughHTMLRenderer) renderStrikethrough(
|
||||||
|
w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
_, _ = w.WriteString("<del")
|
_, _ = w.WriteString("<del")
|
||||||
|
|
|
@ -23,7 +23,7 @@ type escapedPipeCell struct {
|
||||||
Transformed bool
|
Transformed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableCellAlignMethod indicates how are table cells aligned in HTML format.indicates how are table cells aligned in HTML format.
|
// TableCellAlignMethod indicates how are table cells aligned in HTML format.
|
||||||
type TableCellAlignMethod int
|
type TableCellAlignMethod int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -181,7 +181,8 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *tableParagraphTransformer) parseRow(segment text.Segment, alignments []ast.Alignment, isHeader bool, reader text.Reader, pc parser.Context) *ast.TableRow {
|
func (b *tableParagraphTransformer) parseRow(segment text.Segment,
|
||||||
|
alignments []ast.Alignment, isHeader bool, reader text.Reader, pc parser.Context) *ast.TableRow {
|
||||||
source := reader.Source()
|
source := reader.Source()
|
||||||
line := segment.Value(source)
|
line := segment.Value(source)
|
||||||
pos := 0
|
pos := 0
|
||||||
|
@ -369,7 +370,8 @@ var TableAttributeFilter = html.GlobalAttributeFilter.Extend(
|
||||||
[]byte("width"), // [Deprecated]
|
[]byte("width"), // [Deprecated]
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *TableHTMLRenderer) renderTable(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *TableHTMLRenderer) renderTable(
|
||||||
|
w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
_, _ = w.WriteString("<table")
|
_, _ = w.WriteString("<table")
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
|
@ -391,7 +393,8 @@ var TableHeaderAttributeFilter = html.GlobalAttributeFilter.Extend(
|
||||||
[]byte("valign"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
[]byte("valign"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *TableHTMLRenderer) renderTableHeader(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *TableHTMLRenderer) renderTableHeader(
|
||||||
|
w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
_, _ = w.WriteString("<thead")
|
_, _ = w.WriteString("<thead")
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
|
@ -418,7 +421,8 @@ var TableRowAttributeFilter = html.GlobalAttributeFilter.Extend(
|
||||||
[]byte("valign"), // [Obsolete since HTML5]
|
[]byte("valign"), // [Obsolete since HTML5]
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *TableHTMLRenderer) renderTableRow(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *TableHTMLRenderer) renderTableRow(
|
||||||
|
w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
_, _ = w.WriteString("<tr")
|
_, _ = w.WriteString("<tr")
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
|
@ -445,12 +449,14 @@ var TableThCellAttributeFilter = html.GlobalAttributeFilter.Extend(
|
||||||
[]byte("charoff"), // [Obsolete since HTML5]
|
[]byte("charoff"), // [Obsolete since HTML5]
|
||||||
|
|
||||||
[]byte("colspan"), // [OK] Number of columns that the cell is to span
|
[]byte("colspan"), // [OK] Number of columns that the cell is to span
|
||||||
[]byte("headers"), // [OK] This attribute contains a list of space-separated strings, each corresponding to the id attribute of the <th> elements that apply to this element
|
[]byte("headers"), // [OK] This attribute contains a list of space-separated
|
||||||
|
// strings, each corresponding to the id attribute of the <th> elements that apply to this element
|
||||||
|
|
||||||
[]byte("height"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
[]byte("height"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
||||||
|
|
||||||
[]byte("rowspan"), // [OK] Number of rows that the cell is to span
|
[]byte("rowspan"), // [OK] Number of rows that the cell is to span
|
||||||
[]byte("scope"), // [OK] This enumerated attribute defines the cells that the header (defined in the <th>) element relates to [NOT OK in <td>]
|
[]byte("scope"), // [OK] This enumerated attribute defines the cells that
|
||||||
|
// the header (defined in the <th>) element relates to [NOT OK in <td>]
|
||||||
|
|
||||||
[]byte("valign"), // [Obsolete since HTML5]
|
[]byte("valign"), // [Obsolete since HTML5]
|
||||||
[]byte("width"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
[]byte("width"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
||||||
|
@ -466,7 +472,8 @@ var TableTdCellAttributeFilter = html.GlobalAttributeFilter.Extend(
|
||||||
[]byte("charoff"), // [Obsolete since HTML5]
|
[]byte("charoff"), // [Obsolete since HTML5]
|
||||||
|
|
||||||
[]byte("colspan"), // [OK] Number of columns that the cell is to span
|
[]byte("colspan"), // [OK] Number of columns that the cell is to span
|
||||||
[]byte("headers"), // [OK] This attribute contains a list of space-separated strings, each corresponding to the id attribute of the <th> elements that apply to this element
|
[]byte("headers"), // [OK] This attribute contains a list of space-separated
|
||||||
|
// strings, each corresponding to the id attribute of the <th> elements that apply to this element
|
||||||
|
|
||||||
[]byte("height"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
[]byte("height"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
||||||
|
|
||||||
|
@ -477,7 +484,8 @@ var TableTdCellAttributeFilter = html.GlobalAttributeFilter.Extend(
|
||||||
[]byte("width"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
[]byte("width"), // [Deprecated since HTML4] [Obsolete since HTML5]
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *TableHTMLRenderer) renderTableCell(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *TableHTMLRenderer) renderTableCell(
|
||||||
|
w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
n := node.(*ast.TableCell)
|
n := node.(*ast.TableCell)
|
||||||
tag := "td"
|
tag := "td"
|
||||||
if n.Parent().Kind() == ast.KindTableHeader {
|
if n.Parent().Kind() == ast.KindTableHeader {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package extension
|
package extension
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
gast "github.com/yuin/goldmark/ast"
|
gast "github.com/yuin/goldmark/ast"
|
||||||
"github.com/yuin/goldmark/extension/ast"
|
"github.com/yuin/goldmark/extension/ast"
|
||||||
|
@ -9,7 +11,6 @@ import (
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
"github.com/yuin/goldmark/text"
|
"github.com/yuin/goldmark/text"
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
"regexp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var taskListRegexp = regexp.MustCompile(`^\[([\sxX])\]\s*`)
|
var taskListRegexp = regexp.MustCompile(`^\[([\sxX])\]\s*`)
|
||||||
|
@ -80,21 +81,22 @@ func (r *TaskCheckBoxHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRe
|
||||||
reg.Register(ast.KindTaskCheckBox, r.renderTaskCheckBox)
|
reg.Register(ast.KindTaskCheckBox, r.renderTaskCheckBox)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *TaskCheckBoxHTMLRenderer) renderTaskCheckBox(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
func (r *TaskCheckBoxHTMLRenderer) renderTaskCheckBox(
|
||||||
|
w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
|
||||||
if !entering {
|
if !entering {
|
||||||
return gast.WalkContinue, nil
|
return gast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
n := node.(*ast.TaskCheckBox)
|
n := node.(*ast.TaskCheckBox)
|
||||||
|
|
||||||
if n.IsChecked {
|
if n.IsChecked {
|
||||||
w.WriteString(`<input checked="" disabled="" type="checkbox"`)
|
_, _ = w.WriteString(`<input checked="" disabled="" type="checkbox"`)
|
||||||
} else {
|
} else {
|
||||||
w.WriteString(`<input disabled="" type="checkbox"`)
|
_, _ = w.WriteString(`<input disabled="" type="checkbox"`)
|
||||||
}
|
}
|
||||||
if r.XHTML {
|
if r.XHTML {
|
||||||
w.WriteString(" /> ")
|
_, _ = w.WriteString(" /> ")
|
||||||
} else {
|
} else {
|
||||||
w.WriteString("> ")
|
_, _ = w.WriteString("> ")
|
||||||
}
|
}
|
||||||
return gast.WalkContinue, nil
|
return gast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,25 +36,25 @@ func getUnclosedCounter(pc parser.Context) *unclosedCounter {
|
||||||
type TypographicPunctuation int
|
type TypographicPunctuation int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// LeftSingleQuote is '
|
// LeftSingleQuote is ' .
|
||||||
LeftSingleQuote TypographicPunctuation = iota + 1
|
LeftSingleQuote TypographicPunctuation = iota + 1
|
||||||
// RightSingleQuote is '
|
// RightSingleQuote is ' .
|
||||||
RightSingleQuote
|
RightSingleQuote
|
||||||
// LeftDoubleQuote is "
|
// LeftDoubleQuote is " .
|
||||||
LeftDoubleQuote
|
LeftDoubleQuote
|
||||||
// RightDoubleQuote is "
|
// RightDoubleQuote is " .
|
||||||
RightDoubleQuote
|
RightDoubleQuote
|
||||||
// EnDash is --
|
// EnDash is -- .
|
||||||
EnDash
|
EnDash
|
||||||
// EmDash is ---
|
// EmDash is --- .
|
||||||
EmDash
|
EmDash
|
||||||
// Ellipsis is ...
|
// Ellipsis is ... .
|
||||||
Ellipsis
|
Ellipsis
|
||||||
// LeftAngleQuote is <<
|
// LeftAngleQuote is << .
|
||||||
LeftAngleQuote
|
LeftAngleQuote
|
||||||
// RightAngleQuote is >>
|
// RightAngleQuote is >> .
|
||||||
RightAngleQuote
|
RightAngleQuote
|
||||||
// Apostrophe is '
|
// Apostrophe is ' .
|
||||||
Apostrophe
|
Apostrophe
|
||||||
|
|
||||||
typographicPunctuationMax
|
typographicPunctuationMax
|
||||||
|
@ -218,7 +218,8 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
|
||||||
if c == '\'' {
|
if c == '\'' {
|
||||||
if s.Substitutions[Apostrophe] != nil {
|
if s.Substitutions[Apostrophe] != nil {
|
||||||
// Handle decade abbrevations such as '90s
|
// Handle decade abbrevations such as '90s
|
||||||
if d.CanOpen && !d.CanClose && len(line) > 3 && util.IsNumeric(line[1]) && util.IsNumeric(line[2]) && line[3] == 's' {
|
if d.CanOpen && !d.CanClose && len(line) > 3 &&
|
||||||
|
util.IsNumeric(line[1]) && util.IsNumeric(line[2]) && line[3] == 's' {
|
||||||
after := rune(' ')
|
after := rune(' ')
|
||||||
if len(line) > 4 {
|
if len(line) > 4 {
|
||||||
after = util.ToRune(line, 4)
|
after = util.ToRune(line, 4)
|
||||||
|
@ -231,7 +232,8 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// special cases: 'twas, 'em, 'net
|
// special cases: 'twas, 'em, 'net
|
||||||
if len(line) > 1 && (unicode.IsPunct(before) || unicode.IsSpace(before)) && (line[1] == 't' || line[1] == 'e' || line[1] == 'n' || line[1] == 'l') {
|
if len(line) > 1 && (unicode.IsPunct(before) || unicode.IsSpace(before)) &&
|
||||||
|
(line[1] == 't' || line[1] == 'e' || line[1] == 'n' || line[1] == 'l') {
|
||||||
node := gast.NewString(s.Substitutions[Apostrophe])
|
node := gast.NewString(s.Substitutions[Apostrophe])
|
||||||
node.SetCode(true)
|
node.SetCode(true)
|
||||||
block.Advance(1)
|
block.Advance(1)
|
||||||
|
@ -239,7 +241,8 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
|
||||||
}
|
}
|
||||||
// Convert normal apostrophes. This is probably more flexible than necessary but
|
// Convert normal apostrophes. This is probably more flexible than necessary but
|
||||||
// converts any apostrophe in between two alphanumerics.
|
// converts any apostrophe in between two alphanumerics.
|
||||||
if len(line) > 1 && (unicode.IsDigit(before) || unicode.IsLetter(before)) && (unicode.IsLetter(util.ToRune(line, 1))) {
|
if len(line) > 1 && (unicode.IsDigit(before) || unicode.IsLetter(before)) &&
|
||||||
|
(unicode.IsLetter(util.ToRune(line, 1))) {
|
||||||
node := gast.NewString(s.Substitutions[Apostrophe])
|
node := gast.NewString(s.Substitutions[Apostrophe])
|
||||||
node.SetCode(true)
|
node.SetCode(true)
|
||||||
block.Advance(1)
|
block.Advance(1)
|
||||||
|
@ -249,11 +252,14 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
|
||||||
if s.Substitutions[LeftSingleQuote] != nil && d.CanOpen && !d.CanClose {
|
if s.Substitutions[LeftSingleQuote] != nil && d.CanOpen && !d.CanClose {
|
||||||
nt := LeftSingleQuote
|
nt := LeftSingleQuote
|
||||||
// special cases: Alice's, I'm, Don't, You'd
|
// special cases: Alice's, I'm, Don't, You'd
|
||||||
if len(line) > 1 && (line[1] == 's' || line[1] == 'm' || line[1] == 't' || line[1] == 'd') && (len(line) < 3 || util.IsPunct(line[2]) || util.IsSpace(line[2])) {
|
if len(line) > 1 && (line[1] == 's' || line[1] == 'm' || line[1] == 't' || line[1] == 'd') &&
|
||||||
|
(len(line) < 3 || util.IsPunct(line[2]) || util.IsSpace(line[2])) {
|
||||||
nt = RightSingleQuote
|
nt = RightSingleQuote
|
||||||
}
|
}
|
||||||
// special cases: I've, I'll, You're
|
// special cases: I've, I'll, You're
|
||||||
if len(line) > 2 && ((line[1] == 'v' && line[2] == 'e') || (line[1] == 'l' && line[2] == 'l') || (line[1] == 'r' && line[2] == 'e')) && (len(line) < 4 || util.IsPunct(line[3]) || util.IsSpace(line[3])) {
|
if len(line) > 2 && ((line[1] == 'v' && line[2] == 'e') ||
|
||||||
|
(line[1] == 'l' && line[2] == 'l') || (line[1] == 'r' && line[2] == 'e')) &&
|
||||||
|
(len(line) < 4 || util.IsPunct(line[3]) || util.IsSpace(line[3])) {
|
||||||
nt = RightSingleQuote
|
nt = RightSingleQuote
|
||||||
}
|
}
|
||||||
if nt == LeftSingleQuote {
|
if nt == LeftSingleQuote {
|
||||||
|
@ -266,8 +272,9 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
if s.Substitutions[RightSingleQuote] != nil {
|
if s.Substitutions[RightSingleQuote] != nil {
|
||||||
// plural possesives and abbreviations: Smiths', doin'
|
// plural possesive and abbreviations: Smiths', doin'
|
||||||
if len(line) > 1 && unicode.IsSpace(util.ToRune(line, 0)) || unicode.IsPunct(util.ToRune(line, 0)) && (len(line) > 2 && !unicode.IsDigit(util.ToRune(line, 1))) {
|
if len(line) > 1 && unicode.IsSpace(util.ToRune(line, 0)) || unicode.IsPunct(util.ToRune(line, 0)) &&
|
||||||
|
(len(line) > 2 && !unicode.IsDigit(util.ToRune(line, 1))) {
|
||||||
node := gast.NewString(s.Substitutions[RightSingleQuote])
|
node := gast.NewString(s.Substitutions[RightSingleQuote])
|
||||||
node.SetCode(true)
|
node.SetCode(true)
|
||||||
block.Advance(1)
|
block.Advance(1)
|
||||||
|
@ -276,7 +283,8 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
|
||||||
}
|
}
|
||||||
if s.Substitutions[RightSingleQuote] != nil && counter.Single > 0 {
|
if s.Substitutions[RightSingleQuote] != nil && counter.Single > 0 {
|
||||||
isClose := d.CanClose && !d.CanOpen
|
isClose := d.CanClose && !d.CanOpen
|
||||||
maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && unicode.IsPunct(util.ToRune(line, 1)) && (len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2])))
|
maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && unicode.IsPunct(util.ToRune(line, 1)) &&
|
||||||
|
(len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2])))
|
||||||
if isClose || maybeClose {
|
if isClose || maybeClose {
|
||||||
node := gast.NewString(s.Substitutions[RightSingleQuote])
|
node := gast.NewString(s.Substitutions[RightSingleQuote])
|
||||||
node.SetCode(true)
|
node.SetCode(true)
|
||||||
|
@ -296,7 +304,8 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
|
||||||
}
|
}
|
||||||
if s.Substitutions[RightDoubleQuote] != nil && counter.Double > 0 {
|
if s.Substitutions[RightDoubleQuote] != nil && counter.Double > 0 {
|
||||||
isClose := d.CanClose && !d.CanOpen
|
isClose := d.CanClose && !d.CanOpen
|
||||||
maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && (unicode.IsPunct(util.ToRune(line, 1))) && (len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2])))
|
maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && (unicode.IsPunct(util.ToRune(line, 1))) &&
|
||||||
|
(len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2])))
|
||||||
if isClose || maybeClose {
|
if isClose || maybeClose {
|
||||||
// special case: "Monitor 21""
|
// special case: "Monitor 21""
|
||||||
if len(line) > 1 && line[1] == '"' && unicode.IsDigit(before) {
|
if len(line) > 1 && line[1] == '"' && unicode.IsDigit(before) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
var attrNameID = []byte("id")
|
var attrNameID = []byte("id")
|
||||||
var attrNameClass = []byte("class")
|
var attrNameClass = []byte("class")
|
||||||
|
|
||||||
// An Attribute is an attribute of the markdown elements
|
// An Attribute is an attribute of the markdown elements.
|
||||||
type Attribute struct {
|
type Attribute struct {
|
||||||
Name []byte
|
Name []byte
|
||||||
Value interface{}
|
Value interface{}
|
||||||
|
@ -93,7 +93,8 @@ func parseAttribute(reader text.Reader) (Attribute, bool) {
|
||||||
// CommonMark is basically defined for XHTML(even though it is legacy).
|
// CommonMark is basically defined for XHTML(even though it is legacy).
|
||||||
// So we restrict id characters.
|
// So we restrict id characters.
|
||||||
for ; i < len(line) && !util.IsSpace(line[i]) &&
|
for ; i < len(line) && !util.IsSpace(line[i]) &&
|
||||||
(!util.IsPunct(line[i]) || line[i] == '_' || line[i] == '-' || line[i] == ':' || line[i] == '.'); i++ {
|
(!util.IsPunct(line[i]) || line[i] == '_' ||
|
||||||
|
line[i] == '-' || line[i] == ':' || line[i] == '.'); i++ {
|
||||||
}
|
}
|
||||||
name := attrNameClass
|
name := attrNameClass
|
||||||
if c == '#' {
|
if c == '#' {
|
||||||
|
@ -145,7 +146,7 @@ func parseAttributeValue(reader text.Reader) (interface{}, bool) {
|
||||||
reader.SkipSpaces()
|
reader.SkipSpaces()
|
||||||
c := reader.Peek()
|
c := reader.Peek()
|
||||||
var value interface{}
|
var value interface{}
|
||||||
ok := false
|
var ok bool
|
||||||
switch c {
|
switch c {
|
||||||
case text.EOF:
|
case text.EOF:
|
||||||
return Attribute{}, false
|
return Attribute{}, false
|
||||||
|
@ -244,7 +245,7 @@ func scanAttributeDecimal(reader text.Reader, w io.ByteWriter) {
|
||||||
for {
|
for {
|
||||||
c := reader.Peek()
|
c := reader.Peek()
|
||||||
if util.IsNumeric(c) {
|
if util.IsNumeric(c) {
|
||||||
w.WriteByte(c)
|
_ = w.WriteByte(c)
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -286,7 +287,7 @@ func parseAttributeNumber(reader text.Reader) (float64, bool) {
|
||||||
}
|
}
|
||||||
scanAttributeDecimal(reader, &buf)
|
scanAttributeDecimal(reader, &buf)
|
||||||
}
|
}
|
||||||
f, err := strconv.ParseFloat(buf.String(), 10)
|
f, err := strconv.ParseFloat(buf.String(), 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ type HeadingConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOption implements SetOptioner.
|
// SetOption implements SetOptioner.
|
||||||
func (b *HeadingConfig) SetOption(name OptionName, value interface{}) {
|
func (b *HeadingConfig) SetOption(name OptionName, _ interface{}) {
|
||||||
switch name {
|
switch name {
|
||||||
case optAutoHeadingID:
|
case optAutoHeadingID:
|
||||||
b.AutoHeadingID = true
|
b.AutoHeadingID = true
|
||||||
|
@ -135,7 +135,9 @@ func (b *atxHeadingParser) Open(parent ast.Node, reader text.Reader, pc Context)
|
||||||
for _, attr := range attrs {
|
for _, attr := range attrs {
|
||||||
node.SetAttribute(attr.Name, attr.Value)
|
node.SetAttribute(attr.Name, attr.Value)
|
||||||
}
|
}
|
||||||
node.Lines().Append(text.NewSegment(segment.Start+start+1-segment.Padding, segment.Start+closureOpen-segment.Padding))
|
node.Lines().Append(text.NewSegment(
|
||||||
|
segment.Start+start+1-segment.Padding,
|
||||||
|
segment.Start+closureOpen-segment.Padding))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,12 +66,12 @@ func (d *Delimiter) Dump(source []byte, level int) {
|
||||||
|
|
||||||
var kindDelimiter = ast.NewNodeKind("Delimiter")
|
var kindDelimiter = ast.NewNodeKind("Delimiter")
|
||||||
|
|
||||||
// Kind implements Node.Kind
|
// Kind implements Node.Kind.
|
||||||
func (d *Delimiter) Kind() ast.NodeKind {
|
func (d *Delimiter) Kind() ast.NodeKind {
|
||||||
return kindDelimiter
|
return kindDelimiter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Text implements Node.Text
|
// Text implements Node.Text.
|
||||||
func (d *Delimiter) Text(source []byte) []byte {
|
func (d *Delimiter) Text(source []byte) []byte {
|
||||||
return d.Segment.Value(source)
|
return d.Segment.Value(source)
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ func ScanDelimiter(line []byte, before rune, min int, processor DelimiterProcess
|
||||||
after = util.ToRune(line, j)
|
after = util.ToRune(line, j)
|
||||||
}
|
}
|
||||||
|
|
||||||
canOpen, canClose := false, false
|
var canOpen, canClose bool
|
||||||
beforeIsPunctuation := util.IsPunctRune(before)
|
beforeIsPunctuation := util.IsPunctRune(before)
|
||||||
beforeIsWhitespace := util.IsSpaceRune(before)
|
beforeIsWhitespace := util.IsSpaceRune(before)
|
||||||
afterIsPunctuation := util.IsPunctRune(after)
|
afterIsPunctuation := util.IsPunctRune(after)
|
||||||
|
|
|
@ -76,7 +76,7 @@ var allowedBlockTags = map[string]bool{
|
||||||
"ul": true,
|
"ul": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
var htmlBlockType1OpenRegexp = regexp.MustCompile(`(?i)^[ ]{0,3}<(script|pre|style|textarea)(?:\s.*|>.*|/>.*|)(?:\r\n|\n)?$`)
|
var htmlBlockType1OpenRegexp = regexp.MustCompile(`(?i)^[ ]{0,3}<(script|pre|style|textarea)(?:\s.*|>.*|/>.*|)(?:\r\n|\n)?$`) //nolint:golint,lll
|
||||||
var htmlBlockType1CloseRegexp = regexp.MustCompile(`(?i)^.*</(?:script|pre|style|textarea)>.*`)
|
var htmlBlockType1CloseRegexp = regexp.MustCompile(`(?i)^.*</(?:script|pre|style|textarea)>.*`)
|
||||||
|
|
||||||
var htmlBlockType2OpenRegexp = regexp.MustCompile(`^[ ]{0,3}<!\-\-`)
|
var htmlBlockType2OpenRegexp = regexp.MustCompile(`^[ ]{0,3}<!\-\-`)
|
||||||
|
@ -91,9 +91,9 @@ var htmlBlockType4Close = []byte{'>'}
|
||||||
var htmlBlockType5OpenRegexp = regexp.MustCompile(`^[ ]{0,3}<\!\[CDATA\[`)
|
var htmlBlockType5OpenRegexp = regexp.MustCompile(`^[ ]{0,3}<\!\[CDATA\[`)
|
||||||
var htmlBlockType5Close = []byte{']', ']', '>'}
|
var htmlBlockType5Close = []byte{']', ']', '>'}
|
||||||
|
|
||||||
var htmlBlockType6Regexp = regexp.MustCompile(`^[ ]{0,3}<(?:/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(?:[ ].*|>.*|/>.*|)(?:\r\n|\n)?$`)
|
var htmlBlockType6Regexp = regexp.MustCompile(`^[ ]{0,3}<(?:/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(?:[ ].*|>.*|/>.*|)(?:\r\n|\n)?$`) //nolint:golint,lll
|
||||||
|
|
||||||
var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(` + attributePattern + `*)[ ]*(?:>|/>)[ ]*(?:\r\n|\n)?$`)
|
var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/[ ]*)?([a-zA-Z]+[a-zA-Z0-9\-]*)(` + attributePattern + `*)[ ]*(?:>|/>)[ ]*(?:\r\n|\n)?$`) //nolint:golint,lll
|
||||||
|
|
||||||
type htmlBlockParser struct {
|
type htmlBlockParser struct {
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,8 @@ func (b *htmlBlockParser) Open(parent ast.Node, reader text.Reader, pc Context)
|
||||||
_, ok := allowedBlockTags[tagName]
|
_, ok := allowedBlockTags[tagName]
|
||||||
if ok {
|
if ok {
|
||||||
node = ast.NewHTMLBlock(ast.HTMLBlockType6)
|
node = ast.NewHTMLBlock(ast.HTMLBlockType6)
|
||||||
} else if tagName != "script" && tagName != "style" && tagName != "pre" && !ast.IsParagraph(last) && !(isCloseTag && hasAttr) { // type 7 can not interrupt paragraph
|
} else if tagName != "script" && tagName != "style" &&
|
||||||
|
tagName != "pre" && !ast.IsParagraph(last) && !(isCloseTag && hasAttr) { // type 7 can not interrupt paragraph
|
||||||
node = ast.NewHTMLBlock(ast.HTMLBlockType7)
|
node = ast.NewHTMLBlock(ast.HTMLBlockType7)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,8 @@ var linkFindClosureOptions text.FindClosureOptions = text.FindClosureOptions{
|
||||||
Advance: true,
|
Advance: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linkParser) parseReferenceLink(parent ast.Node, last *linkLabelState, block text.Reader, pc Context) (*ast.Link, bool) {
|
func (s *linkParser) parseReferenceLink(parent ast.Node, last *linkLabelState,
|
||||||
|
block text.Reader, pc Context) (*ast.Link, bool) {
|
||||||
_, orgpos := block.Position()
|
_, orgpos := block.Position()
|
||||||
block.Advance(1) // skip '['
|
block.Advance(1) // skip '['
|
||||||
segments, found := block.FindClosure('[', ']', linkFindClosureOptions)
|
segments, found := block.FindClosure('[', ']', linkFindClosureOptions)
|
||||||
|
|
|
@ -22,7 +22,7 @@ var listItemFlagValue interface{} = true
|
||||||
|
|
||||||
// Same as
|
// Same as
|
||||||
// `^(([ ]*)([\-\*\+]))(\s+.*)?\n?$`.FindSubmatchIndex or
|
// `^(([ ]*)([\-\*\+]))(\s+.*)?\n?$`.FindSubmatchIndex or
|
||||||
// `^(([ ]*)(\d{1,9}[\.\)]))(\s+.*)?\n?$`.FindSubmatchIndex
|
// `^(([ ]*)(\d{1,9}[\.\)]))(\s+.*)?\n?$`.FindSubmatchIndex.
|
||||||
func parseListItem(line []byte) ([6]int, listItemType) {
|
func parseListItem(line []byte) ([6]int, listItemType) {
|
||||||
i := 0
|
i := 0
|
||||||
l := len(line)
|
l := len(line)
|
||||||
|
@ -89,7 +89,7 @@ func matchesListItem(source []byte, strict bool) ([6]int, listItemType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcListOffset(source []byte, match [6]int) int {
|
func calcListOffset(source []byte, match [6]int) int {
|
||||||
offset := 0
|
var offset int
|
||||||
if match[4] < 0 || util.IsBlank(source[match[4]:]) { // list item starts with a blank line
|
if match[4] < 0 || util.IsBlank(source[match[4]:]) { // list item starts with a blank line
|
||||||
offset = 1
|
offset = 1
|
||||||
} else {
|
} else {
|
||||||
|
@ -250,14 +250,14 @@ func (b *listParser) Close(node ast.Node, reader text.Reader, pc Context) {
|
||||||
for c := node.FirstChild(); c != nil && list.IsTight; c = c.NextSibling() {
|
for c := node.FirstChild(); c != nil && list.IsTight; c = c.NextSibling() {
|
||||||
if c.FirstChild() != nil && c.FirstChild() != c.LastChild() {
|
if c.FirstChild() != nil && c.FirstChild() != c.LastChild() {
|
||||||
for c1 := c.FirstChild().NextSibling(); c1 != nil; c1 = c1.NextSibling() {
|
for c1 := c.FirstChild().NextSibling(); c1 != nil; c1 = c1.NextSibling() {
|
||||||
if bl, ok := c1.(ast.Node); ok && bl.HasBlankPreviousLines() {
|
if c1.HasBlankPreviousLines() {
|
||||||
list.IsTight = false
|
list.IsTight = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c != node.FirstChild() {
|
if c != node.FirstChild() {
|
||||||
if bl, ok := c.(ast.Node); ok && bl.HasBlankPreviousLines() {
|
if c.HasBlankPreviousLines() {
|
||||||
list.IsTight = false
|
list.IsTight = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,7 +403,8 @@ func (p *parseContext) IsInLinkLabel() bool {
|
||||||
type State int
|
type State int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
none State = 1 << iota
|
// None is a default value of the [State].
|
||||||
|
None State = 1 << iota
|
||||||
|
|
||||||
// Continue indicates parser can continue parsing.
|
// Continue indicates parser can continue parsing.
|
||||||
Continue
|
Continue
|
||||||
|
@ -1049,7 +1050,7 @@ func isBlankLine(lineNum, level int, stats []lineStat) bool {
|
||||||
func (p *parser) parseBlocks(parent ast.Node, reader text.Reader, pc Context) {
|
func (p *parser) parseBlocks(parent ast.Node, reader text.Reader, pc Context) {
|
||||||
pc.SetOpenedBlocks([]Block{})
|
pc.SetOpenedBlocks([]Block{})
|
||||||
blankLines := make([]lineStat, 0, 128)
|
blankLines := make([]lineStat, 0, 128)
|
||||||
isBlank := false
|
var isBlank bool
|
||||||
for { // process blocks separated by blank lines
|
for { // process blocks separated by blank lines
|
||||||
_, lines, ok := reader.SkipBlankLines()
|
_, lines, ok := reader.SkipBlankLines()
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -1152,18 +1153,23 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
lineLength := len(line)
|
lineLength := len(line)
|
||||||
var lineBreakFlags uint8 = 0
|
var lineBreakFlags uint8
|
||||||
hasNewLine := line[lineLength-1] == '\n'
|
hasNewLine := line[lineLength-1] == '\n'
|
||||||
if ((lineLength >= 3 && line[lineLength-2] == '\\' && line[lineLength-3] != '\\') || (lineLength == 2 && line[lineLength-2] == '\\')) && hasNewLine { // ends with \\n
|
if ((lineLength >= 3 && line[lineLength-2] == '\\' &&
|
||||||
|
line[lineLength-3] != '\\') || (lineLength == 2 && line[lineLength-2] == '\\')) && hasNewLine { // ends with \\n
|
||||||
lineLength -= 2
|
lineLength -= 2
|
||||||
lineBreakFlags |= lineBreakHard | lineBreakVisible
|
lineBreakFlags |= lineBreakHard | lineBreakVisible
|
||||||
} else if ((lineLength >= 4 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r' && line[lineLength-4] != '\\') || (lineLength == 3 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r')) && hasNewLine { // ends with \\r\n
|
} else if ((lineLength >= 4 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r' &&
|
||||||
|
line[lineLength-4] != '\\') || (lineLength == 3 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r')) &&
|
||||||
|
hasNewLine { // ends with \\r\n
|
||||||
lineLength -= 3
|
lineLength -= 3
|
||||||
lineBreakFlags |= lineBreakHard | lineBreakVisible
|
lineBreakFlags |= lineBreakHard | lineBreakVisible
|
||||||
} else if lineLength >= 3 && line[lineLength-3] == ' ' && line[lineLength-2] == ' ' && hasNewLine { // ends with [space][space]\n
|
} else if lineLength >= 3 && line[lineLength-3] == ' ' && line[lineLength-2] == ' ' &&
|
||||||
|
hasNewLine { // ends with [space][space]\n
|
||||||
lineLength -= 3
|
lineLength -= 3
|
||||||
lineBreakFlags |= lineBreakHard
|
lineBreakFlags |= lineBreakHard
|
||||||
} else if lineLength >= 4 && line[lineLength-4] == ' ' && line[lineLength-3] == ' ' && line[lineLength-2] == '\r' && hasNewLine { // ends with [space][space]\r\n
|
} else if lineLength >= 4 && line[lineLength-4] == ' ' && line[lineLength-3] == ' ' &&
|
||||||
|
line[lineLength-2] == '\r' && hasNewLine { // ends with [space][space]\r\n
|
||||||
lineLength -= 4
|
lineLength -= 4
|
||||||
lineBreakFlags |= lineBreakHard
|
lineBreakFlags |= lineBreakHard
|
||||||
} else if hasNewLine {
|
} else if hasNewLine {
|
||||||
|
|
|
@ -15,7 +15,7 @@ type rawHTMLParser struct {
|
||||||
var defaultRawHTMLParser = &rawHTMLParser{}
|
var defaultRawHTMLParser = &rawHTMLParser{}
|
||||||
|
|
||||||
// NewRawHTMLParser return a new InlineParser that can parse
|
// NewRawHTMLParser return a new InlineParser that can parse
|
||||||
// inline htmls
|
// inline htmls.
|
||||||
func NewRawHTMLParser() InlineParser {
|
func NewRawHTMLParser() InlineParser {
|
||||||
return defaultRawHTMLParser
|
return defaultRawHTMLParser
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func (s *rawHTMLParser) Parse(parent ast.Node, block text.Reader, pc Context) as
|
||||||
|
|
||||||
var tagnamePattern = `([A-Za-z][A-Za-z0-9-]*)`
|
var tagnamePattern = `([A-Za-z][A-Za-z0-9-]*)`
|
||||||
var spaceOrOneNewline = `(?:[ \t]|(?:\r\n|\n){0,1})`
|
var spaceOrOneNewline = `(?:[ \t]|(?:\r\n|\n){0,1})`
|
||||||
var attributePattern = `(?:[\r\n \t]+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:[\r\n \t]*=[\r\n \t]*(?:[^\"'=<>` + "`" + `\x00-\x20]+|'[^']*'|"[^"]*"))?)`
|
var attributePattern = `(?:[\r\n \t]+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:[\r\n \t]*=[\r\n \t]*(?:[^\"'=<>` + "`" + `\x00-\x20]+|'[^']*'|"[^"]*"))?)` //nolint:golint,lll
|
||||||
var openTagRegexp = regexp.MustCompile("^<" + tagnamePattern + attributePattern + `*` + spaceOrOneNewline + `*/?>`)
|
var openTagRegexp = regexp.MustCompile("^<" + tagnamePattern + attributePattern + `*` + spaceOrOneNewline + `*/?>`)
|
||||||
var closeTagRegexp = regexp.MustCompile("^</" + tagnamePattern + spaceOrOneNewline + `*>`)
|
var closeTagRegexp = regexp.MustCompile("^</" + tagnamePattern + spaceOrOneNewline + `*>`)
|
||||||
|
|
||||||
|
@ -153,9 +153,8 @@ func (s *rawHTMLParser) parseMultiLineRegexp(reg *regexp.Regexp, block text.Read
|
||||||
if l == eline {
|
if l == eline {
|
||||||
block.Advance(end - start)
|
block.Advance(end - start)
|
||||||
break
|
break
|
||||||
} else {
|
|
||||||
block.AdvanceLine()
|
|
||||||
}
|
}
|
||||||
|
block.AdvanceLine()
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ func (b *setextHeadingParser) Close(node ast.Node, reader text.Reader, pc Contex
|
||||||
para.Lines().Append(segment)
|
para.Lines().Append(segment)
|
||||||
heading.Parent().InsertAfter(heading.Parent(), heading, para)
|
heading.Parent().InsertAfter(heading.Parent(), heading, para)
|
||||||
} else {
|
} else {
|
||||||
next.(ast.Node).Lines().Unshift(segment)
|
next.Lines().Unshift(segment)
|
||||||
}
|
}
|
||||||
heading.Parent().RemoveChild(heading.Parent(), heading)
|
heading.Parent().RemoveChild(heading.Parent(), heading)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package html implements renderer that outputs HTMLs.
|
||||||
package html
|
package html
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -253,15 +254,17 @@ var GlobalAttributeFilter = util.NewBytesFilter(
|
||||||
[]byte("translate"),
|
[]byte("translate"),
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Renderer) renderDocument(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderDocument(
|
||||||
|
w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HeadingAttributeFilter defines attribute names which heading elements can have
|
// HeadingAttributeFilter defines attribute names which heading elements can have.
|
||||||
var HeadingAttributeFilter = GlobalAttributeFilter
|
var HeadingAttributeFilter = GlobalAttributeFilter
|
||||||
|
|
||||||
func (r *Renderer) renderHeading(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderHeading(
|
||||||
|
w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
n := node.(*ast.Heading)
|
n := node.(*ast.Heading)
|
||||||
if entering {
|
if entering {
|
||||||
_, _ = w.WriteString("<h")
|
_, _ = w.WriteString("<h")
|
||||||
|
@ -278,12 +281,13 @@ func (r *Renderer) renderHeading(w util.BufWriter, source []byte, node ast.Node,
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockquoteAttributeFilter defines attribute names which blockquote elements can have
|
// BlockquoteAttributeFilter defines attribute names which blockquote elements can have.
|
||||||
var BlockquoteAttributeFilter = GlobalAttributeFilter.Extend(
|
var BlockquoteAttributeFilter = GlobalAttributeFilter.Extend(
|
||||||
[]byte("cite"),
|
[]byte("cite"),
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Renderer) renderBlockquote(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderBlockquote(
|
||||||
|
w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
if entering {
|
if entering {
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
_, _ = w.WriteString("<blockquote")
|
_, _ = w.WriteString("<blockquote")
|
||||||
|
@ -308,7 +312,8 @@ func (r *Renderer) renderCodeBlock(w util.BufWriter, source []byte, n ast.Node,
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) renderFencedCodeBlock(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderFencedCodeBlock(
|
||||||
|
w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
n := node.(*ast.FencedCodeBlock)
|
n := node.(*ast.FencedCodeBlock)
|
||||||
if entering {
|
if entering {
|
||||||
_, _ = w.WriteString("<pre><code")
|
_, _ = w.WriteString("<pre><code")
|
||||||
|
@ -326,7 +331,8 @@ func (r *Renderer) renderFencedCodeBlock(w util.BufWriter, source []byte, node a
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) renderHTMLBlock(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderHTMLBlock(
|
||||||
|
w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
n := node.(*ast.HTMLBlock)
|
n := node.(*ast.HTMLBlock)
|
||||||
if entering {
|
if entering {
|
||||||
if r.Unsafe {
|
if r.Unsafe {
|
||||||
|
@ -428,7 +434,7 @@ func (r *Renderer) renderParagraph(w util.BufWriter, source []byte, n ast.Node,
|
||||||
|
|
||||||
func (r *Renderer) renderTextBlock(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderTextBlock(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
if !entering {
|
if !entering {
|
||||||
if _, ok := n.NextSibling().(ast.Node); ok && n.FirstChild() != nil {
|
if n.NextSibling() != nil && n.FirstChild() != nil {
|
||||||
_ = w.WriteByte('\n')
|
_ = w.WriteByte('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,7 +450,8 @@ var ThematicAttributeFilter = GlobalAttributeFilter.Extend(
|
||||||
[]byte("width"), // [Deprecated]
|
[]byte("width"), // [Deprecated]
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Renderer) renderThematicBreak(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderThematicBreak(
|
||||||
|
w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
if !entering {
|
if !entering {
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
}
|
}
|
||||||
|
@ -473,7 +480,8 @@ var LinkAttributeFilter = GlobalAttributeFilter.Extend(
|
||||||
[]byte("target"),
|
[]byte("target"),
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Renderer) renderAutoLink(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderAutoLink(
|
||||||
|
w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
n := node.(*ast.AutoLink)
|
n := node.(*ast.AutoLink)
|
||||||
if !entering {
|
if !entering {
|
||||||
return ast.WalkContinue, nil
|
return ast.WalkContinue, nil
|
||||||
|
@ -528,7 +536,8 @@ func (r *Renderer) renderCodeSpan(w util.BufWriter, source []byte, n ast.Node, e
|
||||||
// EmphasisAttributeFilter defines attribute names which emphasis elements can have.
|
// EmphasisAttributeFilter defines attribute names which emphasis elements can have.
|
||||||
var EmphasisAttributeFilter = GlobalAttributeFilter
|
var EmphasisAttributeFilter = GlobalAttributeFilter
|
||||||
|
|
||||||
func (r *Renderer) renderEmphasis(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderEmphasis(
|
||||||
|
w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
n := node.(*ast.Emphasis)
|
n := node.(*ast.Emphasis)
|
||||||
tag := "em"
|
tag := "em"
|
||||||
if n.Level == 2 {
|
if n.Level == 2 {
|
||||||
|
@ -618,7 +627,8 @@ func (r *Renderer) renderImage(w util.BufWriter, source []byte, node ast.Node, e
|
||||||
return ast.WalkSkipChildren, nil
|
return ast.WalkSkipChildren, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Renderer) renderRawHTML(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
func (r *Renderer) renderRawHTML(
|
||||||
|
w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
if !entering {
|
if !entering {
|
||||||
return ast.WalkSkipChildren, nil
|
return ast.WalkSkipChildren, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ type Config struct {
|
||||||
NodeRenderers util.PrioritizedSlice
|
NodeRenderers util.PrioritizedSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig returns a new Config
|
// NewConfig returns a new Config.
|
||||||
func NewConfig() *Config {
|
func NewConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Options: map[OptionName]interface{}{},
|
Options: map[OptionName]interface{}{},
|
||||||
|
@ -78,7 +78,7 @@ type NodeRenderer interface {
|
||||||
RegisterFuncs(NodeRendererFuncRegisterer)
|
RegisterFuncs(NodeRendererFuncRegisterer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A NodeRendererFuncRegisterer registers
|
// A NodeRendererFuncRegisterer registers given NodeRendererFunc to this object.
|
||||||
type NodeRendererFuncRegisterer interface {
|
type NodeRendererFuncRegisterer interface {
|
||||||
// Register registers given NodeRendererFunc to this object.
|
// Register registers given NodeRendererFunc to this object.
|
||||||
Register(ast.NodeKind, NodeRendererFunc)
|
Register(ast.NodeKind, NodeRendererFunc)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Package text provides functionalities to manipulate texts.
|
||||||
|
package text
|
|
@ -76,7 +76,7 @@ type Reader interface {
|
||||||
FindClosure(opener, closer byte, options FindClosureOptions) (*Segments, bool)
|
FindClosure(opener, closer byte, options FindClosureOptions) (*Segments, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindClosureOptions is options for Reader.FindClosure
|
// FindClosureOptions is options for Reader.FindClosure.
|
||||||
type FindClosureOptions struct {
|
type FindClosureOptions struct {
|
||||||
// CodeSpan is a flag for the FindClosure. If this is set to true,
|
// CodeSpan is a flag for the FindClosure. If this is set to true,
|
||||||
// FindClosure ignores closers in codespans.
|
// FindClosure ignores closers in codespans.
|
||||||
|
@ -154,7 +154,7 @@ func (r *reader) PeekLine() ([]byte, Segment) {
|
||||||
return nil, r.pos
|
return nil, r.pos
|
||||||
}
|
}
|
||||||
|
|
||||||
// io.RuneReader interface
|
// io.RuneReader interface.
|
||||||
func (r *reader) ReadRune() (rune, int, error) {
|
func (r *reader) ReadRune() (rune, int, error) {
|
||||||
return readRuneReader(r)
|
return readRuneReader(r)
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,7 @@ func (r *blockReader) Value(seg Segment) []byte {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// io.RuneReader interface
|
// io.RuneReader interface.
|
||||||
func (r *blockReader) ReadRune() (rune, int, error) {
|
func (r *blockReader) ReadRune() (rune, int, error) {
|
||||||
return readRuneReader(r)
|
return readRuneReader(r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//nolint:golint,lll,misspell
|
||||||
package util
|
package util
|
||||||
|
|
||||||
// An HTML5Entity struct represents HTML5 entitites.
|
// An HTML5Entity struct represents HTML5 entitites.
|
||||||
|
@ -8,7 +9,7 @@ type HTML5Entity struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookUpHTML5EntityByName returns (an HTML5Entity, true) if an entity named
|
// LookUpHTML5EntityByName returns (an HTML5Entity, true) if an entity named
|
||||||
// given name is found, otherwise (nil, false)
|
// given name is found, otherwise (nil, false).
|
||||||
func LookUpHTML5EntityByName(name string) (*HTML5Entity, bool) {
|
func LookUpHTML5EntityByName(name string) (*HTML5Entity, bool) {
|
||||||
v, ok := html5entities[name]
|
v, ok := html5entities[name]
|
||||||
return v, ok
|
return v, ok
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -63,12 +63,13 @@ func (b *CopyOnWriteBuffer) AppendString(value string) {
|
||||||
|
|
||||||
// WriteByte writes the given byte to the buffer.
|
// WriteByte writes the given byte to the buffer.
|
||||||
// WriteByte allocate new buffer and clears it at the first time.
|
// WriteByte allocate new buffer and clears it at the first time.
|
||||||
func (b *CopyOnWriteBuffer) WriteByte(c byte) {
|
func (b *CopyOnWriteBuffer) WriteByte(c byte) error {
|
||||||
if !b.copied {
|
if !b.copied {
|
||||||
b.buffer = make([]byte, 0, len(b.buffer)+20)
|
b.buffer = make([]byte, 0, len(b.buffer)+20)
|
||||||
b.copied = true
|
b.copied = true
|
||||||
}
|
}
|
||||||
b.buffer = append(b.buffer, c)
|
b.buffer = append(b.buffer, c)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendByte appends given bytes to the buffer.
|
// AppendByte appends given bytes to the buffer.
|
||||||
|
@ -145,12 +146,12 @@ func TabWidth(currentPos int) int {
|
||||||
// If the line contains tab characters, paddings may be not zero.
|
// If the line contains tab characters, paddings may be not zero.
|
||||||
// currentPos==0 and width==2:
|
// currentPos==0 and width==2:
|
||||||
//
|
//
|
||||||
// position: 0 1
|
// position: 0 1
|
||||||
// [TAB]aaaa
|
// [TAB]aaaa
|
||||||
// width: 1234 5678
|
// width: 1234 5678
|
||||||
//
|
//
|
||||||
// width=2 is in the tab character. In this case, IndentPosition returns
|
// width=2 is in the tab character. In this case, IndentPosition returns
|
||||||
// (pos=1, padding=2)
|
// (pos=1, padding=2).
|
||||||
func IndentPosition(bs []byte, currentPos, width int) (pos, padding int) {
|
func IndentPosition(bs []byte, currentPos, width int) (pos, padding int) {
|
||||||
return IndentPositionPadding(bs, currentPos, 0, width)
|
return IndentPositionPadding(bs, currentPos, 0, width)
|
||||||
}
|
}
|
||||||
|
@ -424,7 +425,7 @@ func DoFullUnicodeCaseFolding(v []byte) []byte {
|
||||||
if c >= 0x41 && c <= 0x5a {
|
if c >= 0x41 && c <= 0x5a {
|
||||||
// A-Z to a-z
|
// A-Z to a-z
|
||||||
cob.Write(v[n:i])
|
cob.Write(v[n:i])
|
||||||
cob.WriteByte(c + 32)
|
_ = cob.WriteByte(c + 32)
|
||||||
n = i + 1
|
n = i + 1
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
@ -521,7 +522,7 @@ func ToLinkReference(v []byte) string {
|
||||||
return string(ReplaceSpaces(v, ' '))
|
return string(ReplaceSpaces(v, ' '))
|
||||||
}
|
}
|
||||||
|
|
||||||
var htmlEscapeTable = [256][]byte{nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, []byte("""), nil, nil, nil, []byte("&"), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, []byte("<"), nil, []byte(">"), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
|
var htmlEscapeTable = [256][]byte{nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, []byte("""), nil, nil, nil, []byte("&"), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, []byte("<"), nil, []byte(">"), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} //nolint:golint,lll
|
||||||
|
|
||||||
// EscapeHTMLByte returns HTML escaped bytes if the given byte should be escaped,
|
// EscapeHTMLByte returns HTML escaped bytes if the given byte should be escaped,
|
||||||
// otherwise nil.
|
// otherwise nil.
|
||||||
|
@ -557,7 +558,7 @@ func UnescapePunctuations(source []byte) []byte {
|
||||||
c := source[i]
|
c := source[i]
|
||||||
if i < limit-1 && c == '\\' && IsPunct(source[i+1]) {
|
if i < limit-1 && c == '\\' && IsPunct(source[i+1]) {
|
||||||
cob.Write(source[n:i])
|
cob.Write(source[n:i])
|
||||||
cob.WriteByte(source[i+1])
|
_ = cob.WriteByte(source[i+1])
|
||||||
i += 2
|
i += 2
|
||||||
n = i
|
n = i
|
||||||
continue
|
continue
|
||||||
|
@ -573,9 +574,9 @@ func UnescapePunctuations(source []byte) []byte {
|
||||||
// ResolveNumericReferences resolve numeric references like 'Ӓ" .
|
// ResolveNumericReferences resolve numeric references like 'Ӓ" .
|
||||||
func ResolveNumericReferences(source []byte) []byte {
|
func ResolveNumericReferences(source []byte) []byte {
|
||||||
cob := NewCopyOnWriteBuffer(source)
|
cob := NewCopyOnWriteBuffer(source)
|
||||||
buf := make([]byte, 6, 6)
|
buf := make([]byte, 6)
|
||||||
limit := len(source)
|
limit := len(source)
|
||||||
ok := false
|
var ok bool
|
||||||
n := 0
|
n := 0
|
||||||
for i := 0; i < limit; i++ {
|
for i := 0; i < limit; i++ {
|
||||||
if source[i] == '&' {
|
if source[i] == '&' {
|
||||||
|
@ -625,7 +626,7 @@ func ResolveNumericReferences(source []byte) []byte {
|
||||||
func ResolveEntityNames(source []byte) []byte {
|
func ResolveEntityNames(source []byte) []byte {
|
||||||
cob := NewCopyOnWriteBuffer(source)
|
cob := NewCopyOnWriteBuffer(source)
|
||||||
limit := len(source)
|
limit := len(source)
|
||||||
ok := false
|
var ok bool
|
||||||
n := 0
|
n := 0
|
||||||
for i := 0; i < limit; i++ {
|
for i := 0; i < limit; i++ {
|
||||||
if source[i] == '&' {
|
if source[i] == '&' {
|
||||||
|
@ -658,9 +659,9 @@ var htmlSpace = []byte("%20")
|
||||||
|
|
||||||
// URLEscape escape the given URL.
|
// URLEscape escape the given URL.
|
||||||
// If resolveReference is set true:
|
// If resolveReference is set true:
|
||||||
// 1. unescape punctuations
|
// 1. unescape punctuations
|
||||||
// 2. resolve numeric references
|
// 2. resolve numeric references
|
||||||
// 3. resolve entity references
|
// 3. resolve entity references
|
||||||
//
|
//
|
||||||
// URL encoded values (%xx) are kept as is.
|
// URL encoded values (%xx) are kept as is.
|
||||||
func URLEscape(v []byte, resolveReference bool) []byte {
|
func URLEscape(v []byte, resolveReference bool) []byte {
|
||||||
|
@ -750,7 +751,7 @@ func FindURLIndex(b []byte) int {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
var emailDomainRegexp = regexp.MustCompile(`^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*`)
|
var emailDomainRegexp = regexp.MustCompile(`^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*`) //nolint:golint,lll
|
||||||
|
|
||||||
// FindEmailIndex returns a stop index value if the given bytes seem an email address.
|
// FindEmailIndex returns a stop index value if the given bytes seem an email address.
|
||||||
func FindEmailIndex(b []byte) int {
|
func FindEmailIndex(b []byte) int {
|
||||||
|
@ -781,18 +782,19 @@ func FindEmailIndex(b []byte) int {
|
||||||
|
|
||||||
var spaces = []byte(" \t\n\x0b\x0c\x0d")
|
var spaces = []byte(" \t\n\x0b\x0c\x0d")
|
||||||
|
|
||||||
var spaceTable = [256]int8{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 99, 99, 99, 99, 99, 99, 99, 99} //nolint:golint,lll
|
||||||
|
|
||||||
var emailTable = [256]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} //nolint:golint,lll
|
||||||
|
|
||||||
|
var emailTable = [256]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //nolint:golint,lll
|
||||||
|
|
||||||
// UTF8Len returns a byte length of the utf-8 character.
|
// UTF8Len returns a byte length of the utf-8 character.
|
||||||
func UTF8Len(b byte) int8 {
|
func UTF8Len(b byte) int8 {
|
||||||
|
@ -836,11 +838,18 @@ func IsAlphaNumeric(c byte) bool {
|
||||||
|
|
||||||
// IsEastAsianWideRune returns trhe if the given rune is an east asian wide character, otherwise false.
|
// IsEastAsianWideRune returns trhe if the given rune is an east asian wide character, otherwise false.
|
||||||
func IsEastAsianWideRune(r rune) bool {
|
func IsEastAsianWideRune(r rune) bool {
|
||||||
|
// https://en.wikipedia.org/wiki/CJK_Symbols_and_Punctuation
|
||||||
|
var CJKSymbolsAndPunctuation = &unicode.RangeTable{
|
||||||
|
R16: []unicode.Range16{
|
||||||
|
{0x3000, 0x303F, 1},
|
||||||
|
},
|
||||||
|
}
|
||||||
return unicode.Is(unicode.Hiragana, r) ||
|
return unicode.Is(unicode.Hiragana, r) ||
|
||||||
unicode.Is(unicode.Katakana, r) ||
|
unicode.Is(unicode.Katakana, r) ||
|
||||||
unicode.Is(unicode.Han, r) ||
|
unicode.Is(unicode.Han, r) ||
|
||||||
unicode.Is(unicode.Lm, r) ||
|
unicode.Is(unicode.Lm, r) ||
|
||||||
unicode.Is(unicode.Hangul, r)
|
unicode.Is(unicode.Hangul, r) ||
|
||||||
|
unicode.Is(CJKSymbolsAndPunctuation, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A BufWriter is a subset of the bufio.Writer .
|
// A BufWriter is a subset of the bufio.Writer .
|
||||||
|
@ -862,7 +871,7 @@ type PrioritizedValue struct {
|
||||||
Priority int
|
Priority int
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrioritizedSlice is a slice of the PrioritizedValues
|
// PrioritizedSlice is a slice of the PrioritizedValues.
|
||||||
type PrioritizedSlice []PrioritizedValue
|
type PrioritizedSlice []PrioritizedValue
|
||||||
|
|
||||||
// Sort sorts the PrioritizedSlice in ascending order.
|
// Sort sorts the PrioritizedSlice in ascending order.
|
||||||
|
@ -977,7 +986,7 @@ func (s *bytesFilter) Contains(b []byte) bool {
|
||||||
}
|
}
|
||||||
h := bytesHash(b) % uint64(len(s.slots))
|
h := bytesHash(b) % uint64(len(s.slots))
|
||||||
slot := s.slots[h]
|
slot := s.slots[h]
|
||||||
if slot == nil || len(slot) == 0 {
|
if len(slot) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, element := range slot {
|
for _, element := range slot {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build appengine || js
|
||||||
// +build appengine js
|
// +build appengine js
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build !appengine && !js
|
||||||
// +build !appengine,!js
|
// +build !appengine,!js
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
|
@ -736,7 +736,7 @@ github.com/vmihailenco/tagparser/v2/internal/parser
|
||||||
# github.com/wagslane/go-password-validator v0.3.0
|
# github.com/wagslane/go-password-validator v0.3.0
|
||||||
## explicit; go 1.16
|
## explicit; go 1.16
|
||||||
github.com/wagslane/go-password-validator
|
github.com/wagslane/go-password-validator
|
||||||
# github.com/yuin/goldmark v1.5.5
|
# github.com/yuin/goldmark v1.5.6
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/yuin/goldmark
|
github.com/yuin/goldmark
|
||||||
github.com/yuin/goldmark/ast
|
github.com/yuin/goldmark/ast
|
||||||
|
|
Loading…
Reference in New Issue