@@ -44,8 +44,12 @@ const (
4444 //this is a end of sentence #tag
4545 // ReTags = `\B#(?P<tag>\w+\.?\w+)`
4646 ReTags = `#(?P<tag>[a-zA-Z0-9_.-]+)`
47+
4748 // #tag:notify
4849 ReNotify = `\b(?P<tag>[a-zA-Z0-9_.-]+):notify`
50+
51+ // Action tags start with @, the regex includes the @ sign
52+ ReActionTag = `@(?P<tag>[a-zA-Z0-9_.-]+)`
4953)
5054
5155var log = logging .GetLogger ("parse" )
@@ -54,40 +58,61 @@ func stripHashTag(s string) string {
5458 return regexp .MustCompile (ReTags ).ReplaceAllString (s , "" )
5559}
5660
61+ // compelte this function
62+ func stripActionTags (s string ) string {
63+ return regexp .MustCompile (ReActionTag ).ReplaceAllString (s , "" )
64+ }
65+
5766// parseTags is a [gosuki.Hook] that extracts tags like #tag from the title of
5867// the bookmark or node.
5968// It takes an item of type *tree.Node or *gosuki.Bookmark, extracts all tags
6069// matching the regex pattern defined in ReTags, appends them to the item's Tags
6170// field, and removes the matched tags from the title. If the item is of an
6271// unsupported type, it returns an error.
6372func parseTags (item any ) error {
64- var regex = regexp .MustCompile (ReTags )
73+ tagRe := regexp .MustCompile (ReTags )
74+ actionTagRe := regexp .MustCompile (ReActionTag )
6575 switch v := item .(type ) {
6676 case * tree.Node :
6777 if v .Tags == nil {
6878 v .Tags = []string {}
6979 }
70- processTags (regex , & v .Title , & v .Tags )
80+ processTags (tagRe , & v .Title , & v .Tags , false )
81+ v .Title = stripHashTag (v .Title )
82+ processTags (actionTagRe , & v .Title , & v .Tags , true )
83+ v .Title = stripActionTags (v .Title )
7184 case * gosuki.Bookmark :
7285 if v .Tags == nil {
7386 v .Tags = []string {}
7487 }
75- processTags (regex , & v .Title , & v .Tags )
88+ processTags (tagRe , & v .Title , & v .Tags , false )
89+ v .Title = stripHashTag (v .Title )
90+ processTags (actionTagRe , & v .Title , & v .Tags , true )
91+ v .Title = stripActionTags (v .Title )
7692 default :
7793 return fmt .Errorf ("unsupported type" )
7894 }
7995 return nil
8096}
8197
82- func processTags (regex * regexp.Regexp , title * string , tags * []string ) {
98+ func processTags (
99+ regex * regexp.Regexp ,
100+ title * string ,
101+ tags * []string ,
102+ withSymbol bool ,
103+ ) {
104+
83105 matches := regex .FindAllStringSubmatch (* title , - 1 )
84106 for _ , m := range matches {
85- * tags = append (* tags , m [1 ])
107+ if withSymbol {
108+ * tags = append (* tags , m [0 ])
109+ } else {
110+ * tags = append (* tags , m [1 ])
111+ }
86112 }
87113 if len (* tags ) > 0 {
88114 log .Tracef ("[hook] found following tags: %s" , * tags )
89115 }
90- * title = stripHashTag (* title )
91116}
92117
93118func ParseNodeTags (n * tree.Node ) error {
0 commit comments