-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change vimeo & youtube embed plugins & README plugin list
- Loading branch information
1 parent
fc090b2
commit 155a78b
Showing
5 changed files
with
73 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package plugin | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
md "github.com/JohannesKaufmann/html-to-markdown" | ||
"github.com/PuerkitoBio/goquery" | ||
) | ||
|
||
var youtubeID = regexp.MustCompile(`youtube\.com\/embed\/([^\&\?\/]+)`) | ||
|
||
// YoutubeEmbed registers a rule (for iframes) and | ||
// returns a markdown compatible representation (link to video, ...). | ||
func YoutubeEmbed() md.Plugin { | ||
return func(c *md.Converter) []md.Rule { | ||
return []md.Rule{ | ||
{ | ||
Filter: []string{"iframe"}, | ||
Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string { | ||
src := selec.AttrOr("src", "") | ||
if !strings.Contains(src, "youtube.com") { | ||
return nil | ||
} | ||
alt := selec.AttrOr("title", "") | ||
|
||
parts := youtubeID.FindStringSubmatch(src) | ||
if len(parts) != 2 { | ||
return nil | ||
} | ||
id := parts[1] | ||
|
||
text := fmt.Sprintf("[![%s](https://img.youtube.com/vi/%s/0.jpg)](https://www.youtube.com/watch?v=%s)", alt, id, id) | ||
return &text | ||
}, | ||
}, | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.