html: Support links with image descriptions

Turns out Org mode supports image links natively and we don't have to go out of
spec!

From https://orgmode.org/manual/Images-in-HTML-export.html:

[...] if the description part of the Org link is itself another link, such as
‘file:’ or ‘http:’ URL pointing to an image, the HTML export back-end in-lines
this image and links to [...]
This commit is contained in:
Niklas Fasching 2020-06-28 21:00:35 +02:00
parent c536adf6e9
commit d85768891c
5 changed files with 33 additions and 10 deletions

View file

@ -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"
}