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

Conversation

ctem
Copy link

@ctem ctem commented Jan 7, 2025

This PR includes two fixes:

  • Remove the # tag prefix to avoid "Malformed entry" errors in Taskwarrior when applying coefficients to tags.
  • Use non-greedy regex to ensure page link-style tags are extracted separately.

The relevant documentation is also updated.

Copy link
Collaborator

@ryneeverett ryneeverett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't entirely follow the non-greedy regex change because I'm not familiar enough with logseq to know what "page link-style tags" are. If you added such a tag to the tests somewhere that would be a nice touch.

@ryneeverett
Copy link
Collaborator

Pinging @scross01 for possible input.

ctem added 3 commits January 8, 2025 14:41
The prefix causes taskwarrior to throw a "Malformed entry" error when
applying a coefficient to the tag.
This ensures that page link-style tags are not inadvertently combined
into a single match.
- The leading '#' is removed from the example tags.
- Typos are corrected.
@ctem ctem force-pushed the fix/logseq-tags branch from 236042f to ccad0f4 Compare January 8, 2025 17:29
ctem added 2 commits January 8, 2025 17:36
Three logseq-compatible tags are added to the test record: two in the
'page link' format and one in the conventional 'tag' format. The
expected results demonstrate:

- issue title: page link double brackets are replaced with special
  characters for taskwarrior compatibility
- tags:
  - the conventional tag is added first
  - non-greedy regex matching prevents the inadvertent combination of
    the two page link tags into a single tag
  - the leading `#` is stripped from all tags
For improved maintainability, the logseq block URI in the expected
results is now dynamically assigned by concatenating the base URI with
the test record UUID.
@ctem ctem force-pushed the fix/logseq-tags branch from ccad0f4 to c991889 Compare January 8, 2025 17:38
@ctem
Copy link
Author

ctem commented Jan 8, 2025

"page link-style tags"

Logseq supports several syntaxes, including:

  • #PageTitle: conventional, no-whitespace tag (called "single-word tag" in bugwarrior docs)
  • [[Page Title]]: page link—not treated as a tag in bugwarrior
  • #[[Page Title]]: "page link-style" tag for whitespace support (called "multi-word tag" in bugwarrior docs)

the non-greedy regex change

I'll try to illustrate the issue with an example procedure:

  1. Consume the logseq issue title:
    TODO Do something #[[Test tag]] #[[TestTag]] #TestTag
  2. Format the title, replacing brackets with respective special characters:
    TODO Do something #【Test tag】 #【TestTag】 #TestTag
  3. Extract tags from the formatted title, starting with conventional tags, then greedily matching page link-style tags (which will match from the first # to the last , resulting in a single match that includes both tags):
    ['#TestTag', '#【Test tag】 #【TestTag】']
  4. Remove whitespace and the special characters from all tags:
    ['#TestTag', '#Testtag#TestTag']
  5. Strip the leading # from all tags for the final result:
    ['TestTag', 'Testtag#TestTag']

By switching to non-greedy matching, the two page link-style tags are matched separately, resulting in the correct final list, ['TestTag', 'Testtag', 'TestTag'], which taskwarrior will ultimately deduplicate to ['TestTag', 'Testtag'].

Hope that makes sense!

Copy link
Collaborator

@ryneeverett ryneeverett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@scross01
Copy link
Contributor

scross01 commented Jan 9, 2025

Nice fix. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants