diff --git a/org/html.go b/org/html.go
index ea7afce..0bb3879 100644
--- a/org/html.go
+++ b/org/html.go
@@ -3,7 +3,6 @@ package org
import (
"fmt"
"html"
- "path"
"strings"
)
@@ -188,20 +187,20 @@ func (w *HTMLWriter) writeFootnoteLink(l FootnoteLink) {
func (w *HTMLWriter) writeRegularLink(l RegularLink) {
url := html.EscapeString(l.URL)
+ if l.Protocol == "file" {
+ url = url[len("file:"):]
+ }
description := url
if l.Description != nil {
descriptionWriter := w.emptyClone()
descriptionWriter.writeNodes(l.Description...)
description = descriptionWriter.String()
}
- switch l.Protocol {
- case "file":
- url = url[len("file:"):]
- if strings.Contains(".png.jpg.jpeg.gif", path.Ext(l.URL)) {
- w.WriteString(fmt.Sprintf(``, url, description, description))
- } else {
- w.WriteString(fmt.Sprintf(`%s`, url, description))
- }
+ switch l.Kind() {
+ case "image":
+ w.WriteString(fmt.Sprintf(`
`, url, description, description))
+ case "video":
+ w.WriteString(fmt.Sprintf(``, url, description, description))
default:
w.WriteString(fmt.Sprintf(`%s`, url, description))
}
diff --git a/org/inline.go b/org/inline.go
index 5b71d8a..e096ae0 100644
--- a/org/inline.go
+++ b/org/inline.go
@@ -1,6 +1,7 @@
package org
import (
+ "path"
"regexp"
"strings"
"unicode"
@@ -29,8 +30,9 @@ type RegularLink struct {
var validURLCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;="
var autolinkProtocols = regexp.MustCompile(`(https?|ftp|file)`)
+var imageExtensionRegexp = regexp.MustCompile(`^[.](png|gif|jpe?g|svg|tiff?)$`)
+var videoExtensionRegexp = regexp.MustCompile(`^[.](webm|mp4)$`)
-var redundantSpaces = regexp.MustCompile("[ \t]+")
var subScriptSuperScriptRegexp = regexp.MustCompile(`([_^])\{(.*?)\}`)
var footnoteRegexp = regexp.MustCompile(`\[fn:([\w-]+?)(:(.*?))?\]`)
@@ -205,3 +207,16 @@ func isValidPostChar(r rune) bool {
}
func isValidBorderChar(r rune) bool { return !unicode.IsSpace(r) }
+
+func (l RegularLink) Kind() string {
+ if p := l.Protocol; l.Description != nil || (p != "" && p != "file" && p != "http" && p != "https") {
+ return "regular"
+ }
+ if imageExtensionRegexp.MatchString(path.Ext(l.URL)) {
+ return "image"
+ }
+ if videoExtensionRegexp.MatchString(path.Ext(l.URL)) {
+ return "video"
+ }
+ return "regular"
+}
diff --git a/org/testdata/example.html b/org/testdata/example.html
index d44ada3..902af7c 100644
--- a/org/testdata/example.html
+++ b/org/testdata/example.html
@@ -162,7 +162,22 @@ regular link example.com link with description
-regular link to a file (image)
+regular link to a file (image)
+
+regular link to a file (video) +
+
+regular link to http (image)
+
+regular link to https (image)