Skip to content

Commit 5f5e968

Browse files
authored
readme: Add description of extras extension
1 parent 234f8fa commit 5f5e968

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

‎README.md‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,63 @@ inline $a^*=x-b^*$ snippet
104104
fmt.Println(buf.String())
105105
}
106106
```
107+
108+
## Extras extension
109+
110+
[![GoDoc](https://godoc.org/github.com/gohugoio/hugo-goldmark-extensions/extras?status.svg)](https://godoc.org/github.com/gohugoio/hugo-goldmark-extensions/extras)
111+
112+
Use this extension to include [inserted text], [mark text], [subscript], and [superscript] elements in Markdown.
113+
114+
Element|Markdown|Rendered
115+
:--|:--|:--
116+
Inserted text|`++foo++`|`<ins>foo</ins>`
117+
Mark text|`==bar==`|`<mark>bar</mark>`
118+
Subscript|`H~2~O`|`H<sub>2</sub>O`
119+
Superscript|`1^st^`|`1<sup>st</sup>`
120+
121+
[inserted text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins
122+
[mark text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark
123+
[subscript]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub
124+
[superscript]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup
125+
126+
### Usage
127+
128+
```go
129+
package main
130+
131+
import (
132+
"bytes"
133+
"fmt"
134+
135+
"github.com/gohugoio/hugo-goldmark-extensions/extras"
136+
"github.com/gohugoio/hugo-goldmark-extensions/extras/ast"
137+
"github.com/yuin/goldmark"
138+
)
139+
140+
func main() {
141+
md := goldmark.New(
142+
goldmark.WithExtensions(
143+
extras.New(extras.Config{InlineTagType: ast.Insert}),
144+
extras.New(extras.Config{InlineTagType: ast.Mark}),
145+
extras.New(extras.Config{InlineTagType: ast.Subscript}),
146+
extras.New(extras.Config{InlineTagType: ast.Superscript}),
147+
))
148+
149+
input := `
150+
Hydrogen (H) is the 1^st^ element in the periodic table.
151+
152+
Water (H~2~O) is a liquid.
153+
154+
Water (H~2~O) is a ++transparent++ liquid.
155+
156+
Water (H~2~O) is a ++transparent++ ==liquid==.
157+
`
158+
159+
var buf bytes.Buffer
160+
if err := md.Convert([]byte(input), &buf); err != nil {
161+
panic(err)
162+
}
163+
164+
fmt.Println(buf.String())
165+
}
166+
```

0 commit comments

Comments
 (0)