Skip to content

Commit 155a78b

Browse files
change vimeo & youtube embed plugins & README plugin list
1 parent fc090b2 commit 155a78b

File tree

5 files changed

+73
-43
lines changed

5 files changed

+73
-43
lines changed

Diff for: README.md

+26
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,32 @@ converter.Use(plugin.Strikethrough(""))
103103

104104
For more information have a look at the example [github_flavored](/examples/github_flavored/main.go).
105105

106+
---
107+
108+
These are the plugins located in the [plugin folder](/plugin) which you can use by importing "github.com/JohannesKaufmann/html-to-markdown/plugin".
109+
110+
| Name | Description |
111+
| --------------------- | ------------------------------------------------------------------------------------------- |
112+
| GitHubFlavored | GitHub's Flavored Markdown contains `TaskListItems`, `Strikethrough` and `Table`. |
113+
| TaskListItems | (Included in `GitHubFlavored`). Converts `<input>` checkboxes into `- [x] Task`. |
114+
| Strikethrough | (Included in `GitHubFlavored`). Converts `<strike>`, `<s>`, and `<del>` to the `~~` syntax. |
115+
| Table | (Included in `GitHubFlavored`). Convert a `<table>` into something like this... |
116+
| TableCompat | |
117+
| | |
118+
| VimeoEmbed | |
119+
| YoutubeEmbed | |
120+
| | |
121+
| ConfluenceCodeBlock | Converts `<ac:structured-macro>` elements that are used in Atlassian’s Wiki "Confluence". |
122+
| ConfluenceAttachments | Converts `<ri:attachment ri:filename=""/>` elements. |
123+
124+
These are the plugins in other repositories:
125+
126+
| Name | Description |
127+
| ---------------------------- | ------------------- |
128+
| \[Plugin Name\]\(Your Link\) | A short description |
129+
130+
I you write a plugin, feel free to open a PR that adds your Plugin to this list.
131+
106132
## Writing Plugins
107133

108134
Have a look at the [plugin folder](/plugin) for a reference implementation. The most basic one is [Strikethrough](/plugin/strikethrough.go).

Diff for: plugin/vimeo.go renamed to plugin/iframe_vimeo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ const (
5454
VimeoWithDescription
5555
)
5656

57-
// EXPERIMENTALVimeoEmbed registers a rule (for iframes) and
57+
// VimeoEmbed registers a rule (for iframes) and
5858
// returns a markdown compatible representation (link to video, ...).
59-
func EXPERIMENTALVimeoEmbed(variation vimeoVariation) md.Plugin {
59+
func VimeoEmbed(variation vimeoVariation) md.Plugin {
6060
return func(c *md.Converter) []md.Rule {
6161
getVimeoData := func(id string) (*vimeoVideo, error) {
6262
u := fmt.Sprintf("http://vimeo.com/api/oembed.json?url=https://vimeo.com/%s", id)

Diff for: plugin/iframe_youtube.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package plugin
2+
3+
import (
4+
"fmt"
5+
"regexp"
6+
"strings"
7+
8+
md "github.com/JohannesKaufmann/html-to-markdown"
9+
"github.com/PuerkitoBio/goquery"
10+
)
11+
12+
var youtubeID = regexp.MustCompile(`youtube\.com\/embed\/([^\&\?\/]+)`)
13+
14+
// YoutubeEmbed registers a rule (for iframes) and
15+
// returns a markdown compatible representation (link to video, ...).
16+
func YoutubeEmbed() md.Plugin {
17+
return func(c *md.Converter) []md.Rule {
18+
return []md.Rule{
19+
{
20+
Filter: []string{"iframe"},
21+
Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
22+
src := selec.AttrOr("src", "")
23+
if !strings.Contains(src, "youtube.com") {
24+
return nil
25+
}
26+
alt := selec.AttrOr("title", "")
27+
28+
parts := youtubeID.FindStringSubmatch(src)
29+
if len(parts) != 2 {
30+
return nil
31+
}
32+
id := parts[1]
33+
34+
text := fmt.Sprintf("[![%s](https://img.youtube.com/vi/%s/0.jpg)](https://www.youtube.com/watch?v=%s)", alt, id, id)
35+
return &text
36+
},
37+
},
38+
}
39+
}
40+
}

Diff for: plugin/table.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/PuerkitoBio/goquery"
99
)
1010

11-
// TableCompat is a compatibility plugon for environments where
11+
// TableCompat is a compatibility plugin for environments where
1212
// only commonmark markdown (without Tables) is supported.
1313
//
1414
// Note: In an environment that supports "real" Tables, like GitHub's Flavored Markdown
@@ -132,10 +132,10 @@ func Table() md.Plugin {
132132
}
133133

134134
// A tr is a heading row if:
135-
// - the parent is a THEAD
136-
// - or if its the first child of the TABLE or the first TBODY (possibly
137-
// following a blank THEAD)
138-
// - and every cell is a TH
135+
// - the parent is a THEAD
136+
// - or if its the first child of the TABLE or the first TBODY (possibly
137+
// following a blank THEAD)
138+
// - and every cell is a TH
139139
func isHeadingRow(s *goquery.Selection) bool {
140140
parent := s.Parent()
141141

Diff for: plugin/youtube.go

-36
This file was deleted.

0 commit comments

Comments
 (0)