Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logseq tag handling #1083

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bugwarrior/docs/services/logseq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ From the command line you can open a specific task using taskwarior task id, e.g
Tags
++++

LogSeq tasks with ``#tag`` style tag entries in the description are added to the Taskwarrior tags.
Multi and single word tags using the Logseq ``#[[Tag]]`` or ``#[[Multi Word]]`` format are
condenced to a ``#Tag`` and ``#MultiWord`` style before adding the Taskwarrior tags. The format of
the tag content in task desciption is unchanged.
Logseq tasks with ``#tag`` style tag entries in the description are added to the Taskwarrior tags.
Single- and multi-word tags using the Logseq ``#[[Tag]]`` or ``#[[Multi Word]]`` format are
condensed to a ``Tag`` and ``MultiWord`` style before adding the Taskwarrior tags. The format of
the tag content in the task description is unchanged.


Troubleshooting
Expand Down
6 changes: 3 additions & 3 deletions bugwarrior/services/logseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def get_tags_from_content(self):
)
# and this adds the #[[multi word]] formatted tags
tags.extend(re.findall(
r"(#[" + self.config.char_open_link + r"].*[" + self.config.char_close_link + r"])",
r"(#[" + self.config.char_open_link + r"].*?[" + self.config.char_close_link + r"])",
self.get_formatted_title()
))
# compress format to single words
tags = [self._compress_tag_format(t) for t in tags]
# compress format to single words and strip leading `#`
tags = [self._compress_tag_format(t).lstrip('#') for t in tags]
return tags

# get a list of annotations from the content
Expand Down
19 changes: 10 additions & 9 deletions tests/test_logseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestLogseqIssue(AbstractServiceTest, ServiceTest):
{"id": 1777},
{"id": 7070},
],
"content": "DOING [#A] Do something",
"content": "DOING [#A] Do something #[[Test tag]] #[[TestTag]] #TestTag",
"properties-text-values": {"duration": '{"TODO":[0,1699562197346]}'},
"marker": "DOING",
"page": {"id": 7070},
Expand All @@ -40,6 +40,7 @@ class TestLogseqIssue(AbstractServiceTest, ServiceTest):
}

test_extra = {
"baseURI": "logseq://graph/Test?block-id=",
"graph": "Test",
}

Expand All @@ -63,12 +64,12 @@ def test_to_taskwarrior(self):
"status": "pending",
"priority": "L",
"project": self.test_extra["graph"],
"tags": [],
"tags": ['TestTag', 'Testtag', 'TestTag'],
issue.ID: int(self.test_record["id"]),
issue.UUID: self.test_record["uuid"],
issue.STATE: self.test_record["marker"],
issue.TITLE: "DOING Do something",
issue.URI: "logseq://graph/Test?block-id=66699a83-3ee0-4edc-81c6-a24c9b80bec6",
issue.TITLE: "DOING Do something #【Test tag】 #【TestTag】 #TestTag",
issue.URI: self.test_extra["baseURI"] + self.test_record["uuid"],
}

actual = issue.to_taskwarrior()
Expand All @@ -83,20 +84,20 @@ def test_issues(self):
expected = {
"annotations": [],
"description": f"(bw)Is#{self.test_record['id']}"
+ " - DOING Do something"
+ " .. logseq://graph/Test?block-id=66699a83-3ee0-4edc-81c6-a24c9b80bec6",
+ " - DOING Do something #【Test tag】 #【TestTag】 #TestTag"
+ " .. " + self.test_extra["baseURI"] + self.test_record["uuid"],
"due": None,
"scheduled": None,
"wait": None,
"status": "pending",
"priority": "L",
"project": self.test_extra["graph"],
"tags": [],
"tags": ['TestTag', 'Testtag', 'TestTag'],
issue.ID: int(self.test_record["id"]),
issue.UUID: self.test_record["uuid"],
issue.STATE: self.test_record["marker"],
issue.TITLE: "DOING Do something",
issue.URI: "logseq://graph/Test?block-id=66699a83-3ee0-4edc-81c6-a24c9b80bec6",
issue.TITLE: "DOING Do something #【Test tag】 #【TestTag】 #TestTag",
issue.URI: self.test_extra["baseURI"] + self.test_record["uuid"],
}

self.assertEqual(TaskConstructor(issue).get_taskwarrior_record(), expected)