summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-11-19 23:06:08 +0200
committerPaul Buetow <paul@buetow.org>2024-11-19 23:06:08 +0200
commit34aec369e7bb0f16399ef357742f19d762fe84b6 (patch)
tree802f06d882776e94916cf253e2937110f737af26
parent836d21a7c43f4ce84dfa1ada0552989be4a43ca9 (diff)
fix bug
-rw-r--r--internal/queue/inlinetags.go8
-rw-r--r--internal/queue/inlinetags_test.go19
2 files changed, 16 insertions, 11 deletions
diff --git a/internal/queue/inlinetags.go b/internal/queue/inlinetags.go
index 11f05c2..5e4455d 100644
--- a/internal/queue/inlinetags.go
+++ b/internal/queue/inlinetags.go
@@ -4,13 +4,15 @@ import (
"fmt"
"os"
"path/filepath"
+ "regexp"
"strings"
"codeberg.org/snonux/gos/internal/colour"
"codeberg.org/snonux/gos/internal/oi"
)
-// TODO: Don't treat it as inline tags when there are other characters tan [a-z,.]
+var inlineTagRE = regexp.MustCompile(`^[a-z\.,:]*$`)
+
// Extracts the inline tags into the filepath and removes them from the content.
func extractInlineTags(filePath string) (string, error) {
content, err := oi.SlurpAndTrim(filePath)
@@ -54,9 +56,7 @@ func extractInlineTagsToFilePath(filePath, content string) (string, string, erro
func extractInlineTagsFromContent(content string) ([]string, string, error) {
parts := strings.Split(content, " ")
- // If the first word of the content contains a dot or comma and there are
- // more than 2 elems, then there are inline tags!
- if strings.Contains(parts[0], ".") || strings.Contains(parts[0], ",") {
+ if inlineTagRE.MatchString(parts[0]) {
var tags []string
for _, elem := range strings.Split(parts[0], ".") {
tags = append(tags, strings.Split(elem, ",")...)
diff --git a/internal/queue/inlinetags_test.go b/internal/queue/inlinetags_test.go
index 8b85cb2..33039f8 100644
--- a/internal/queue/inlinetags_test.go
+++ b/internal/queue/inlinetags_test.go
@@ -32,11 +32,12 @@ func TestExtractInlineTagsToFilePath(t *testing.T) {
func TestExtractInlineTagsFromContent(t *testing.T) {
table := map[string][]string{
- "foo,bar,baz blablablabla...": {"foo", "bar", "baz"},
- "foo.bar.baz blablablabla...": {"foo", "bar", "baz"},
- "foo.bar,baz blablablabla...": {"foo", "bar", "baz"},
- "foo,bar.baz blablablabla...": {"foo", "bar", "baz"},
- "share:li,foo this is the main content": {"share:li", "foo"},
+ "foo,bar,baz blablablabla...": {"foo", "bar", "baz"},
+ "foo.bar.baz blablablabla...": {"foo", "bar", "baz"},
+ "foo.bar,baz blablablabla...": {"foo", "bar", "baz"},
+ "foo,bar.baz blablablabla...": {"foo", "bar", "baz"},
+ "share:li,foo this is the main content": {"share:li", "foo"},
+ "shar()e:li,foo this is the main content": {},
}
for input, expectedTags := range table {
@@ -55,13 +56,17 @@ func TestExtractInlineTagsFromContent(t *testing.T) {
expectedTag, tags)
}
}
+
+ expectedMainContent := input
parts := strings.Split(input, " ")
- expectedMainContent := strings.Join(parts[1:], " ")
+ if inlineTagRE.MatchString(parts[0]) {
+ expectedMainContent = strings.Join(parts[1:], " ")
+ }
+
if contentWithoutTags != expectedMainContent {
t.Errorf("expected the main content to be '%s' but got '%s'",
expectedMainContent, contentWithoutTags)
}
-
})
}
}