Refactor RegularLink: Do not fake description if none is given
To more faithfully handle inline images we need to know whether the original link included a description - being more explicit about that will make it easier. see org.el/org-display-inline-images > An inline image is a link which follows either of these > conventions: > > 1. Its path is a file with an extension matching return value > from `image-file-name-regexp' and it has no contents. > > 2. Its description consists in a single link of the previous > type.
This commit is contained in:
parent
4348505ada
commit
f17923047b
3 changed files with 20 additions and 21 deletions
|
@ -188,9 +188,12 @@ func (w *HTMLWriter) writeFootnoteLink(l FootnoteLink) {
|
|||
|
||||
func (w *HTMLWriter) writeRegularLink(l RegularLink) {
|
||||
url := html.EscapeString(l.URL)
|
||||
description := url
|
||||
if l.Description != nil {
|
||||
descriptionWriter := w.emptyClone()
|
||||
descriptionWriter.writeNodes(l.Description...)
|
||||
description := descriptionWriter.String()
|
||||
description = descriptionWriter.String()
|
||||
}
|
||||
switch l.Protocol {
|
||||
case "file":
|
||||
url = url[len("file:"):]
|
||||
|
|
|
@ -144,8 +144,7 @@ func (d *Document) parseAutoLink(input string, start int) (int, int, Node) {
|
|||
if path == "://" {
|
||||
return 0, 0, nil
|
||||
}
|
||||
link := RegularLink{protocol, []Node{Text{protocol + path}}, protocol + path, true}
|
||||
return len(protocol), len(path + protocol), link
|
||||
return len(protocol), len(path + protocol), RegularLink{protocol, nil, protocol + path, true}
|
||||
}
|
||||
|
||||
func (d *Document) parseRegularLink(input string, start int) (int, Node) {
|
||||
|
@ -157,18 +156,15 @@ func (d *Document) parseRegularLink(input string, start int) (int, Node) {
|
|||
if end == -1 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
rawLink := input[2:end]
|
||||
link, description, parts := "", []Node{}, strings.Split(rawLink, "][")
|
||||
if len(parts) == 2 {
|
||||
link, description = parts[0], d.parseInline(parts[1])
|
||||
} else {
|
||||
link, description = rawLink, []Node{Text{rawLink}}
|
||||
rawLinkParts := strings.Split(input[2:end], "][")
|
||||
description, link := ([]Node)(nil), rawLinkParts[0]
|
||||
if len(rawLinkParts) == 2 {
|
||||
link, description = rawLinkParts[0], d.parseInline(rawLinkParts[1])
|
||||
}
|
||||
consumed := end + 2
|
||||
protocol, parts := "", strings.SplitN(link, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
protocol = parts[0]
|
||||
protocol, linkParts := "", strings.SplitN(link, ":", 2)
|
||||
if len(linkParts) == 2 {
|
||||
protocol = linkParts[0]
|
||||
}
|
||||
return consumed, RegularLink{protocol, description, link, false}
|
||||
}
|
||||
|
|
10
org/org.go
10
org/org.go
|
@ -247,14 +247,14 @@ func (w *OrgWriter) writeFootnoteLink(l FootnoteLink) {
|
|||
}
|
||||
|
||||
func (w *OrgWriter) writeRegularLink(l RegularLink) {
|
||||
if l.AutoLink {
|
||||
w.WriteString(l.URL)
|
||||
} else if l.Description == nil {
|
||||
w.WriteString(fmt.Sprintf("[[%s]]", l.URL))
|
||||
} else {
|
||||
descriptionWriter := w.emptyClone()
|
||||
descriptionWriter.writeNodes(l.Description...)
|
||||
description := descriptionWriter.String()
|
||||
if l.AutoLink {
|
||||
w.WriteString(l.URL)
|
||||
} else if l.URL != description {
|
||||
w.WriteString(fmt.Sprintf("[[%s][%s]]", l.URL, description))
|
||||
} else {
|
||||
w.WriteString(fmt.Sprintf("[[%s]]", l.URL))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue