diff --git a/org/html_writer.go b/org/html_writer.go index 7c5c6d3..3333906 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -341,16 +341,26 @@ func (w *HTMLWriter) WriteRegularLink(l RegularLink) { if prefix := w.document.Links[l.Protocol]; prefix != "" { url = html.EscapeString(prefix) + strings.TrimPrefix(url, l.Protocol+":") } - description := url - if l.Description != nil { - description = w.WriteNodesAsString(l.Description...) - } switch l.Kind() { case "image": - w.WriteString(fmt.Sprintf(`%s`, url, description, description)) + if l.Description == nil { + w.WriteString(fmt.Sprintf(`%s`, url, url, url)) + } else { + description := strings.TrimPrefix(String(l.Description), "file:") + w.WriteString(fmt.Sprintf(`%s`, url, description, description)) + } case "video": - w.WriteString(fmt.Sprintf(``, url, description, description)) + if l.Description == nil { + w.WriteString(fmt.Sprintf(``, url, url, url)) + } else { + description := strings.TrimPrefix(String(l.Description), "file:") + w.WriteString(fmt.Sprintf(``, url, description, description)) + } default: + description := url + if l.Description != nil { + description = w.WriteNodesAsString(l.Description...) + } w.WriteString(fmt.Sprintf(`%s`, url, description)) } } diff --git a/org/inline.go b/org/inline.go index ede3355..e7a8f47 100644 --- a/org/inline.go +++ b/org/inline.go @@ -383,6 +383,14 @@ func isValidPostChar(r rune) bool { func isValidBorderChar(r rune) bool { return !unicode.IsSpace(r) } func (l RegularLink) Kind() string { + description := String(l.Description) + descProtocol, descExt := strings.SplitN(description, ":", 2)[0], path.Ext(description) + if ok := descProtocol == "file" || descProtocol == "http" || descProtocol == "https"; ok && imageExtensionRegexp.MatchString(descExt) { + return "image" + } else if ok && videoExtensionRegexp.MatchString(descExt) { + return "video" + } + if p := l.Protocol; l.Description != nil || (p != "" && p != "file" && p != "http" && p != "https") { return "regular" } diff --git a/org/testdata/inline.html b/org/testdata/inline.html index f2fc773..0df8ec5 100644 --- a/org/testdata/inline.html +++ b/org/testdata/inline.html @@ -76,6 +76,9 @@ not emphasized/

regular link to https (image) https://placekitten.com/200/200#.png

  • +

    regular link with image as description https://placekitten.com/200/200#.png

    +
  • +
  • regular link enclosed in [] [https://www.example.com] [example.com]

  • diff --git a/org/testdata/inline.org b/org/testdata/inline.org index 188e38c..a81e24c 100644 --- a/org/testdata/inline.org +++ b/org/testdata/inline.org @@ -28,8 +28,9 @@ 4. regular link to a file (video) [[my-video.mp4]] 5. regular link to http (image) [[http://placekitten.com/200/200#.png]] 6. regular link to https (image) [[https://placekitten.com/200/200#.png]] - 7. regular link enclosed in [] [[[https://www.example.com]]] [[[https://www.example.com][example.com]]] - 8. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com + 7. regular link with image as description [[https://placekitten.com][https://placekitten.com/200/200#.png]] + 8. regular link enclosed in [] [[[https://www.example.com]]] [[[https://www.example.com][example.com]]] + 9. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com - timestamps - <2019-01-06> - <2019-01-06 Sun> diff --git a/org/testdata/inline.pretty_org b/org/testdata/inline.pretty_org index 60fe598..acf70d6 100644 --- a/org/testdata/inline.pretty_org +++ b/org/testdata/inline.pretty_org @@ -28,8 +28,9 @@ 4. regular link to a file (video) [[my-video.mp4]] 5. regular link to http (image) [[http://placekitten.com/200/200#.png]] 6. regular link to https (image) [[https://placekitten.com/200/200#.png]] - 7. regular link enclosed in [] [[[https://www.example.com]]] [[[https://www.example.com][example.com]]] - 8. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com + 7. regular link with image as description [[https://placekitten.com][https://placekitten.com/200/200#.png]] + 8. regular link enclosed in [] [[[https://www.example.com]]] [[[https://www.example.com][example.com]]] + 9. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com - timestamps - <2019-01-06 Sun> - <2019-01-06 Sun>