diff --git a/org/html.go b/org/html.go
index 1db4ab4..ea7afce 100644
--- a/org/html.go
+++ b/org/html.go
@@ -188,9 +188,12 @@ func (w *HTMLWriter) writeFootnoteLink(l FootnoteLink) {
func (w *HTMLWriter) writeRegularLink(l RegularLink) {
url := html.EscapeString(l.URL)
- descriptionWriter := w.emptyClone()
- descriptionWriter.writeNodes(l.Description...)
- description := descriptionWriter.String()
+ 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:"):]
diff --git a/org/inline.go b/org/inline.go
index df7bade..5b71d8a 100644
--- a/org/inline.go
+++ b/org/inline.go
@@ -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}
}
diff --git a/org/org.go b/org/org.go
index b2aedea..4b77b43 100644
--- a/org/org.go
+++ b/org/org.go
@@ -247,14 +247,14 @@ func (w *OrgWriter) writeFootnoteLink(l FootnoteLink) {
}
func (w *OrgWriter) writeRegularLink(l RegularLink) {
- 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 {
+ } else if l.Description == nil {
w.WriteString(fmt.Sprintf("[[%s]]", l.URL))
+ } else {
+ descriptionWriter := w.emptyClone()
+ descriptionWriter.writeNodes(l.Description...)
+ description := descriptionWriter.String()
+ w.WriteString(fmt.Sprintf("[[%s][%s]]", l.URL, description))
}
}