blob: 22ad7a4fc4d159899a72664622b47b2ba8b1aab1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# goldmark-figure
[](https://pkg.go.dev/github.com/mangoumbrella/goldmark-figure)
[](https://github.com/mangoumbrella/goldmark-figure/actions/workflows/test.yml/badge.svg?event=push)
[](https://goreportcard.com/report/github.com/mangoumbrella/goldmark-figure)
[goldmark-figure](https://github.com/MangoUmbrella/goldmark-figure) is a
[goldmark](http://github.com/yuin/goldmark)
extension to parse mardown paragraphs that start with an image into HTML
`<figure>` elements. One nice thing is it doesn't use any new markdown
syntaxes.
Example markdown source:
```md

Awesome caption about **Oscar** the kitty.
```
Render result:
```html
<figure>
<img src="/path/to/cat.jpg" alt="Picture of Oscar." />
<figcaption>Awesome caption about <strong>Oscar</strong> the kitty.</figcaption>
</figure>
```
# Installation
```
go get github.com/mangoumbrella/goldmark-figure
```
# Usage
```go
import (
"bytes"
"fmt"
"github.com/mangoumbrella/goldmark-figure"
"github.com/yuin/goldmark"
)
func main() {
markdown := goldmark.New(
goldmark.WithExtensions(
figure.Figure,
),
)
source := `

Awesome caption about **Oscar** the kitty.
`
var buf bytes.Buffer
if err := markdown.Convert([]byte(source), &buf); err != nil {
panic(err)
}
fmt.Print(buf.String())
}
```
See [`figure_test.go`](/figure_test.go) for detailed usages.
# LICENSE
MIT
# Authors
Yilei Yang
|