From 5f5e9689146ef711f87c2a30f989093a55a42f8e Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 3 May 2024 17:43:37 -0700 Subject: [PATCH] readme: Add description of extras extension --- README.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/README.md b/README.md index 2682f8a..43ef441 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,63 @@ inline $a^*=x-b^*$ snippet fmt.Println(buf.String()) } ``` + +## Extras extension + +[![GoDoc](https://godoc.org/github.com/gohugoio/hugo-goldmark-extensions/extras?status.svg)](https://godoc.org/github.com/gohugoio/hugo-goldmark-extensions/extras) + +Use this extension to include [inserted text], [mark text], [subscript], and [superscript] elements in Markdown. + +Element|Markdown|Rendered +:--|:--|:-- +Inserted text|`++foo++`|`foo` +Mark text|`==bar==`|`bar` +Subscript|`H~2~O`|`H2O` +Superscript|`1^st^`|`1st` + +[inserted text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins +[mark text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark +[subscript]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub +[superscript]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup + +### Usage + +```go +package main + +import ( + "bytes" + "fmt" + + "github.com/gohugoio/hugo-goldmark-extensions/extras" + "github.com/gohugoio/hugo-goldmark-extensions/extras/ast" + "github.com/yuin/goldmark" +) + +func main() { + md := goldmark.New( + goldmark.WithExtensions( + extras.New(extras.Config{InlineTagType: ast.Insert}), + extras.New(extras.Config{InlineTagType: ast.Mark}), + extras.New(extras.Config{InlineTagType: ast.Subscript}), + extras.New(extras.Config{InlineTagType: ast.Superscript}), + )) + + input := ` +Hydrogen (H) is the 1^st^ element in the periodic table. + +Water (H~2~O) is a liquid. + +Water (H~2~O) is a ++transparent++ liquid. + +Water (H~2~O) is a ++transparent++ ==liquid==. + ` + + var buf bytes.Buffer + if err := md.Convert([]byte(input), &buf); err != nil { + panic(err) + } + + fmt.Println(buf.String()) +} +```