diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-19 10:56:44 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-19 10:56:44 +0200 |
| commit | 744c3b70fa590345f6c1de715e2a572f184091c4 (patch) | |
| tree | d198cf86b5afe2fbc7af42fdb0b1262c2f5bc30c /internal/entry/entry.go | |
| parent | f2318c4946db3ffd60a2b955e47660c2f77007df (diff) | |
initial inline to file path extraction
Diffstat (limited to 'internal/entry/entry.go')
| -rw-r--r-- | internal/entry/entry.go | 32 |
1 files changed, 1 insertions, 31 deletions
diff --git a/internal/entry/entry.go b/internal/entry/entry.go index 1237c3e..7c574a0 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -106,14 +106,12 @@ func (en *Entry) Content() (string, []string, error) { return content, extractURLs(content), err } -// Returns the content and also checks for the size limit and also removes any -// inline tags. +// Returns the content and also checks for the size limit func (en Entry) ContentWithLimit(sizeLimit int) (string, []string, error) { content, urls, err := en.Content() if err != nil { return "", urls, err } - _, content, _ = extractInlineTags(content) if len(content) > sizeLimit { err := fmt.Errorf("%w (%d > %d): %v", ErrSizeLimitExceeded, len(content), sizeLimit, en) if err2 := prompt.Acknowledge("You need to shorten the content as "+err.Error(), content); err2 != nil { @@ -190,36 +188,8 @@ func (en Entry) extractTags(parts []string) { } } -func (en Entry) ExtractInlineTags() error { - content, _, err := en.Content() - if err != nil { - return err - } - if tags, _, ok := extractInlineTags(content); ok { - en.extractTags(tags) - } - return nil -} - func extractURLs(input string) []string { urlPattern := `(http://|https://|ftp://)[^\s]+` re := regexp.MustCompile(urlPattern) return re.FindAllString(input, -1) } - -// Returns inline tags, real content. And true when there were inline tags. -func extractInlineTags(content string) ([]string, string, bool) { - 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], ",") { - var tags []string - for _, elem := range strings.Split(parts[0], ".") { - tags = append(tags, strings.Split(elem, ",")...) - } - if len(tags) > 1 { - return tags, strings.Join(parts[1:], " "), true - } - } - return []string{}, content, false -} |
