summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-01-15 21:30:28 +0200
committerPaul Buetow <paul@buetow.org>2025-01-15 21:30:28 +0200
commit5c3813b593415615116acbe8d21f262c1f20e9f8 (patch)
tree614c4aeec89c24587eee7123b9a901aceb4b6788 /internal
parent94d9b5f48147ee9cc6ca57177e00f8679224603d (diff)
fix bug in regards to inline tags extractions involving newlines
Diffstat (limited to 'internal')
-rw-r--r--internal/tags/inline.go5
-rw-r--r--internal/tags/inline_test.go10
2 files changed, 11 insertions, 4 deletions
diff --git a/internal/tags/inline.go b/internal/tags/inline.go
index da31acf..a4d90cc 100644
--- a/internal/tags/inline.go
+++ b/internal/tags/inline.go
@@ -57,7 +57,7 @@ func inlineExtractTagsFromContent(content string) ([]string, string, error) {
isShare := func(tag string) bool {
return strings.HasPrefix(tag, "share:")
}
- parts := strings.Split(content, " ")
+ parts := strings.Fields(content)
// First word must contain certain symbols to clarify as (inline) tags.
if !inlineTagRE.MatchString(parts[0]) {
return []string{}, content, nil
@@ -77,7 +77,8 @@ func inlineExtractTagsFromContent(content string) ([]string, string, error) {
}
}
}
- return tags, strings.TrimSpace(strings.Join(parts[1:], " ")), nil
+ content = strings.TrimPrefix(content, parts[0])
+ return tags, strings.TrimSpace(content), nil
}
return []string{}, content, nil
diff --git a/internal/tags/inline_test.go b/internal/tags/inline_test.go
index 9fafcf8..af089ed 100644
--- a/internal/tags/inline_test.go
+++ b/internal/tags/inline_test.go
@@ -17,6 +17,7 @@ func TestInlineExtractTagsToFilePath(t *testing.T) {
"share:li,foo this is the main content": "./gosdir/foo.golang.rox.share:linkedin.foo.extracted.txt",
"share:li:ma this is the main content": "./gosdir/foo.golang.rox.share:linkedin:mastodon.extracted.txt",
"share:li:ma,now this is the main content": "./gosdir/foo.golang.rox.share:linkedin:mastodon.now.extracted.txt",
+ "share,soon this will be shared soon": "./gosdir/foo.golang.rox.share.soon.extracted.txt",
}
for content, expectedFilePath := range table {
@@ -42,6 +43,11 @@ func TestInlineExtractTagsFromContent(t *testing.T) {
"share:li,foo this is the main content": {"share:linkedin", "foo"},
"shar()e:li,foo this is the main content": {"shar()e:li", "foo"},
"share this post": {},
+ "share,soon the main content here": {"share", "soon"},
+ `share,soon
+
+ the main content here
+ #foo`: {"share", "soon"},
}
for input, expectedTags := range table {
@@ -63,9 +69,9 @@ func TestInlineExtractTagsFromContent(t *testing.T) {
}
expectedMainContent := input
- parts := strings.Split(input, " ")
+ parts := strings.Fields(input)
if inlineTagRE.MatchString(parts[0]) {
- expectedMainContent = strings.Join(parts[1:], " ")
+ expectedMainContent = strings.TrimPrefix(expectedMainContent, parts[0])
}
if contentWithoutTags != strings.TrimSpace(expectedMainContent) {