-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade to goldmark v1.7.8, handle Node.Text deprecation (#163)
- Loading branch information
Showing
8 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package goldast | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
"github.com/yuin/goldmark/ast" | ||
) | ||
|
||
// Text returns the text for the [ast.String] and [ast.Text] nodes | ||
// in the tree of the given goldmark AST node. | ||
func Text(src []byte, n ast.Node) []byte { | ||
var buf bytes.Buffer | ||
writeNodeText(src, &buf, n) | ||
return buf.Bytes() | ||
} | ||
|
||
func writeNodeText(src []byte, dst io.Writer, n ast.Node) { | ||
switch n := n.(type) { | ||
case *ast.Text: | ||
_, _ = dst.Write(n.Segment.Value(src)) | ||
case *ast.String: | ||
_, _ = dst.Write(n.Value) | ||
default: | ||
for c := n.FirstChild(); c != nil; c = c.NextSibling() { | ||
writeNodeText(src, dst, c) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters