diff options
Diffstat (limited to 'vendor/github.com/yuin/goldmark/extension')
8 files changed, 44 insertions, 11 deletions
diff --git a/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go b/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go index 1beffb3..0ff7412 100644 --- a/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go +++ b/vendor/github.com/yuin/goldmark/extension/ast/definition_list.go @@ -17,6 +17,14 @@ func (n *DefinitionList) Dump(source []byte, level int) { gast.DumpHelper(n, source, level, nil, nil) } +// Pos implements Node.Pos. +func (n *DefinitionList) Pos() int { + if n.FirstChild() != nil { + return n.FirstChild().Pos() + } + return -1 +} + // KindDefinitionList is a NodeKind of the DefinitionList node. var KindDefinitionList = gast.NewNodeKind("DefinitionList") @@ -44,6 +52,14 @@ func (n *DefinitionTerm) Dump(source []byte, level int) { gast.DumpHelper(n, source, level, nil, nil) } +// Pos implements Node.Pos. +func (n *DefinitionTerm) Pos() int { + if n.Lines().Len() == 0 { + return -1 + } + return n.Lines().At(0).Start +} + // KindDefinitionTerm is a NodeKind of the DefinitionTerm node. var KindDefinitionTerm = gast.NewNodeKind("DefinitionTerm") diff --git a/vendor/github.com/yuin/goldmark/extension/ast/table.go b/vendor/github.com/yuin/goldmark/extension/ast/table.go index 4142e33..ba87048 100644 --- a/vendor/github.com/yuin/goldmark/extension/ast/table.go +++ b/vendor/github.com/yuin/goldmark/extension/ast/table.go @@ -123,6 +123,7 @@ func (n *TableHeader) Dump(source []byte, level int) { // NewTableHeader returns a new TableHeader node. func NewTableHeader(row *TableRow) *TableHeader { n := &TableHeader{} + n.SetPos(row.Pos()) for c := row.FirstChild(); c != nil; { next := c.NextSibling() n.AppendChild(n, c) diff --git a/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go b/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go index 670cc14..16abf95 100644 --- a/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go +++ b/vendor/github.com/yuin/goldmark/extension/ast/tasklist.go @@ -2,6 +2,7 @@ package ast import ( "fmt" + gast "github.com/yuin/goldmark/ast" ) diff --git a/vendor/github.com/yuin/goldmark/extension/definition_list.go b/vendor/github.com/yuin/goldmark/extension/definition_list.go index 3e64dcf..b7a86c0 100644 --- a/vendor/github.com/yuin/goldmark/extension/definition_list.go +++ b/vendor/github.com/yuin/goldmark/extension/definition_list.go @@ -130,7 +130,7 @@ func (b *definitionDescriptionParser) Open( if para != nil { lines := para.Lines() l := lines.Len() - for i := 0; i < l; i++ { + for i := range l { term := ast.NewDefinitionTerm() segment := lines.At(i) term.Lines().Append(segment.TrimRightSpace(reader.Source())) diff --git a/vendor/github.com/yuin/goldmark/extension/footnote.go b/vendor/github.com/yuin/goldmark/extension/footnote.go index 2e22526..30eb85c 100644 --- a/vendor/github.com/yuin/goldmark/extension/footnote.go +++ b/vendor/github.com/yuin/goldmark/extension/footnote.go @@ -321,7 +321,7 @@ func NewFootnoteConfig() FootnoteConfig { } // SetOption implements renderer.SetOptioner. -func (c *FootnoteConfig) SetOption(name renderer.OptionName, value interface{}) { +func (c *FootnoteConfig) SetOption(name renderer.OptionName, value any) { switch name { case optFootnoteIDPrefixFunction: c.IDPrefixFunction = value.(func(gast.Node) []byte) diff --git a/vendor/github.com/yuin/goldmark/extension/linkify.go b/vendor/github.com/yuin/goldmark/extension/linkify.go index ad88933..f76e31d 100644 --- a/vendor/github.com/yuin/goldmark/extension/linkify.go +++ b/vendor/github.com/yuin/goldmark/extension/linkify.go @@ -32,7 +32,7 @@ const ( ) // SetOption implements SetOptioner. -func (c *LinkifyConfig) SetOption(name parser.OptionName, value interface{}) { +func (c *LinkifyConfig) SetOption(name parser.OptionName, value any) { switch name { case optLinkifyAllowedProtocols: c.AllowedProtocols = value.([][]byte) @@ -211,9 +211,10 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont } else if lastChar == ')' { closing := 0 for i := m[1] - 1; i >= m[0]; i-- { - if line[i] == ')' { + switch line[i] { + case ')': closing++ - } else if line[i] == '(' { + case '(': closing-- } } @@ -254,7 +255,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont } at := bytes.IndexByte(line, '@') m = []int{0, stop, at, stop - 1} - if m == nil || bytes.IndexByte(line[m[2]:m[3]], '.') < 0 { + if bytes.IndexByte(line[m[2]:m[3]], '.') < 0 { return nil } lastChar := line[m[1]-1] diff --git a/vendor/github.com/yuin/goldmark/extension/table.go b/vendor/github.com/yuin/goldmark/extension/table.go index ee782a2..1d74182 100644 --- a/vendor/github.com/yuin/goldmark/extension/table.go +++ b/vendor/github.com/yuin/goldmark/extension/table.go @@ -68,7 +68,7 @@ func NewTableConfig() TableConfig { } // SetOption implements renderer.SetOptioner. -func (c *TableConfig) SetOption(name renderer.OptionName, value interface{}) { +func (c *TableConfig) SetOption(name renderer.OptionName, value any) { switch name { case optTableCellAlignMethod: c.TableCellAlignMethod = value.(TableCellAlignMethod) @@ -125,12 +125,16 @@ func isTableDelim(bs []byte) bool { if w, _ := util.IndentWidth(bs, 0); w > 3 { return false } + allSep := true for _, b := range bs { + if b != '-' { + allSep = false + } if !(util.IsSpace(b) || b == '-' || b == '|' || b == ':') { return false } } - return true + return !allSep } var tableDelimLeft = regexp.MustCompile(`^\s*\:\-+\s*$`) @@ -150,6 +154,7 @@ func NewTableParagraphTransformer() parser.ParagraphTransformer { } func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text.Reader, pc parser.Context) { + ppos := node.Pos() lines := node.Lines() if lines.Len() < 2 { return @@ -165,6 +170,7 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text. } table := ast.NewTable() table.Alignments = alignments + table.SetPos(ppos) table.AppendChild(table, ast.NewTableHeader(header)) for j := i + 1; j < lines.Len(); j++ { table.AppendChild(table, b.parseRow(lines.At(j), alignments, false, reader, pc)) @@ -183,6 +189,7 @@ 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 { + npos := segment source := reader.Source() segment = segment.TrimLeftSpace(source) segment = segment.TrimRightSpace(source) @@ -190,6 +197,7 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, pos := 0 limit := len(line) row := ast.NewTableRow(alignments) + row.SetPos(npos.Start) if len(line) > 0 && line[pos] == '|' { pos++ } @@ -209,6 +217,7 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, var escapedCell *escapedPipeCell node := ast.NewTableCell() + node.SetPos(npos.Start + pos - npos.Padding) node.Alignment = alignment hasBacktick := false closure := pos @@ -223,7 +232,7 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, if escapedCell == nil { escapedCell = &escapedPipeCell{node, []int{}, false} escapedList := pc.ComputeIfAbsent(escapedPipeCellListKey, - func() interface{} { + func() any { return []*escapedPipeCell{} }).([]*escapedPipeCell) escapedList = append(escapedList, escapedCell) @@ -502,7 +511,12 @@ func (r *TableHTMLRenderer) renderTableCell( v, ok := n.AttributeString("style") var cob util.CopyOnWriteBuffer if ok { - cob = util.NewCopyOnWriteBuffer(v.([]byte)) + switch v := v.(type) { + case []byte: + cob = util.NewCopyOnWriteBuffer(v) + case string: + cob = util.NewCopyOnWriteBuffer([]byte(v)) + } cob.AppendByte(';') } style := fmt.Sprintf("text-align:%s", n.Alignment.String()) diff --git a/vendor/github.com/yuin/goldmark/extension/typographer.go b/vendor/github.com/yuin/goldmark/extension/typographer.go index 44c15eb..3a3f106 100644 --- a/vendor/github.com/yuin/goldmark/extension/typographer.go +++ b/vendor/github.com/yuin/goldmark/extension/typographer.go @@ -83,7 +83,7 @@ func newDefaultSubstitutions() [][]byte { } // SetOption implements SetOptioner. -func (b *TypographerConfig) SetOption(name parser.OptionName, value interface{}) { +func (b *TypographerConfig) SetOption(name parser.OptionName, value any) { switch name { case optTypographicSubstitutions: b.Substitutions = value.([][]byte) |
