Browse Source

Problem: tags are not parsed server side

Solution: add parsing of tags to server side
master
Peter Stuifzand 4 months ago
parent
commit
f79a01ae9b
  1. 18
      util.go

18
util.go

@ -132,7 +132,8 @@ func ParseLinks(blockId string, content string) ([]ParsedLink, error) { @@ -132,7 +132,8 @@ func ParseLinks(blockId string, content string) ([]ParsedLink, error) {
}
func ParseTags(content string) ([]string, error) {
hrefRE := regexp.MustCompile(`(#\[\[\s*([^\]]+)\s*\]\])`)
linkRE := regexp.MustCompile(`(#\[\[\s*([^\]]+)\s*\]\])`)
tagRE := regexp.MustCompile(`#([^ ]+)`)
scanner := bufio.NewScanner(strings.NewReader(content))
scanner.Split(bufio.ScanLines)
@ -141,13 +142,16 @@ func ParseTags(content string) ([]string, error) { @@ -141,13 +142,16 @@ func ParseTags(content string) ([]string, error) {
for scanner.Scan() {
line := scanner.Text()
links := hrefRE.FindAllStringSubmatch(line, -1)
links := linkRE.FindAllStringSubmatch(line, -1)
for _, matches := range links {
link := matches[0]
link = strings.TrimPrefix(link, "#[[")
link = strings.TrimSuffix(link, "]]")
link = strings.TrimSpace(link)
result = append(result, link)
linkText := matches[0]
linkText = strings.TrimPrefix(linkText, "#[[")
linkText = strings.TrimSuffix(linkText, "]]")
linkText = strings.TrimSpace(linkText)
result = append(result, linkText)
}
for _, matches := range tagRE.FindAllStringSubmatch(line, -1) {
result = append(result, matches[1])
}
}

Loading…
Cancel
Save