fix if statement logic

pull/391/head
tjex 4 months ago
parent 2e1b80d59a
commit 7d26750eac

@ -7,12 +7,12 @@ import (
"strings" "strings"
"unicode/utf16" "unicode/utf16"
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
"github.com/zk-org/zk/internal/core" "github.com/zk-org/zk/internal/core"
"github.com/zk-org/zk/internal/util" "github.com/zk-org/zk/internal/util"
"github.com/zk-org/zk/internal/util/errors" "github.com/zk-org/zk/internal/util/errors"
strutil "github.com/zk-org/zk/internal/util/strings" strutil "github.com/zk-org/zk/internal/util/strings"
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
) )
// documentStore holds opened documents. // documentStore holds opened documents.
@ -228,24 +228,25 @@ func (d *document) DocumentLinks() ([]documentLink, error) {
}) })
} }
// extract link paths from [title](path) patterns // extract link paths from [title](path) patterns
for _, match := range for _, match := range markdownLinkRegex.FindAllStringSubmatchIndex(line, -1) {
markdownLinkRegex.FindAllStringSubmatchIndex(line, -1) { // Ignore embedded images ![title](file.png) and tripple dash file
// case: '!' ignores embedded image, e.g. ![title](href.png) // URIs [title](file:///file.go)
// case: '/' ignores tripple dash file URIs, e.g. file:///file.go if (match[0] > 0 && line[match[0]-1] == '!') ||
if match[0] > 0 && line[match[0]-1] == '!' || line[match[3]+8] == '/' { (match[0] > 0 && line[match[3]+8] == '/') {
continue continue
} }
href := line[match[4]:match[5]] href := line[match[4]:match[5]]
// Valid Markdown links are percent-encoded.
// Decode the href if it's percent-encoded
if decodedHref, err := url.PathUnescape(href); err == nil { if decodedHref, err := url.PathUnescape(href); err == nil {
href = decodedHref href = decodedHref
} }
appendLink(href, match[0], match[1], false, false) appendLink(href, match[0], match[1], false, false)
} }
for _, match := range wikiLinkRegex.FindAllStringSubmatchIndex(line, -1) { for _, match := range wikiLinkRegex.FindAllStringSubmatchIndex(line, -1) {
href := line[match[2]:match[3]] href := line[match[2]:match[3]]
hasTitle := match[4] != -1 hasTitle := match[4] != -1

Loading…
Cancel
Save