Simplify tag parsing logic. No in-tag commas.
This commit is contained in:
parent
2c4060ca88
commit
f8c48d0415
@ -187,7 +187,7 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
|
|||||||
- If the URL contains characters like `;`, `&` or brackets they may be interpreted specially by the shell. To avoid it, add the URL within single or double (`'`/`"`) quotes.
|
- If the URL contains characters like `;`, `&` or brackets they may be interpreted specially by the shell. To avoid it, add the URL within single or double (`'`/`"`) quotes.
|
||||||
- URLs are unique in DB. The same URL cannot be added twice. You can update tags and re-fetch title data.
|
- URLs are unique in DB. The same URL cannot be added twice. You can update tags and re-fetch title data.
|
||||||
- **Tags**:
|
- **Tags**:
|
||||||
- Comma (`,`) is the tag delimiter in DB. Tags are filtered (for unique tags) and sorted. Hence, any tag cannot have comma(s) in it. In-tag commas are replaced by spaces.
|
- Comma (`,`) is the tag delimiter in DB. Any tag cannot have comma(s) in it. Tags are filtered (for unique tags) and sorted.
|
||||||
- **Update** operation:
|
- **Update** operation:
|
||||||
- If --title, --tag or --comment is passed without argument, clear the corresponding field from DB.
|
- If --title, --tag or --comment is passed without argument, clear the corresponding field from DB.
|
||||||
- If --url is passed (and --title is omitted), update the title from web using the URL.
|
- If --url is passed (and --title is omitted), update the title from web using the URL.
|
||||||
|
38
buku
38
buku
@ -877,42 +877,36 @@ def network_handler(url):
|
|||||||
|
|
||||||
def parse_tags(keywords=[]):
|
def parse_tags(keywords=[]):
|
||||||
"""Format and get tag string from tokens"""
|
"""Format and get tag string from tokens"""
|
||||||
# TODO: Simplify this logic
|
|
||||||
|
|
||||||
tags = DELIMITER
|
tags = DELIMITER
|
||||||
origTags = []
|
origTags = []
|
||||||
uniqueTags = []
|
uniqueTags = []
|
||||||
|
|
||||||
# Cleanse and get the tags
|
# Cleanse and get the tags
|
||||||
for tag in keywords:
|
tagstr = ' '.join(keywords)
|
||||||
if tag == '':
|
marker = tagstr.find(',')
|
||||||
|
|
||||||
|
while marker >= 0:
|
||||||
|
token = tagstr[0:marker]
|
||||||
|
tagstr = tagstr[marker+1:]
|
||||||
|
marker = tagstr.find(',')
|
||||||
|
token = token.strip()
|
||||||
|
if token == '':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if tag[0] == DELIMITER: # delimiter precedes token (e.g. token1 ,token2)
|
tags += token + ','
|
||||||
if tags[-1] != DELIMITER:
|
|
||||||
tags += DELIMITER
|
|
||||||
|
|
||||||
if tag[-1] == DELIMITER: # if delimiter is present, maintain it (e.g. token1, token2)
|
tagstr = tagstr.strip()
|
||||||
tag = tag.strip(DELIMITER).replace(DELIMITER, ' ') + DELIMITER
|
if tagstr != '':
|
||||||
else: # a token in a multi-word tag (e.g. token1 token2)
|
tags += tagstr + ','
|
||||||
tag = tag.strip(DELIMITER).replace(DELIMITER, ' ')
|
|
||||||
|
|
||||||
if tag == DELIMITER: # isolated delimiter (e.g. token1 , token2)
|
if debug:
|
||||||
if tags[-1] != DELIMITER:
|
print(keywords)
|
||||||
tags += tag
|
print('tags: [%s]' % tags)
|
||||||
continue
|
|
||||||
|
|
||||||
if tags[-1] == DELIMITER:
|
|
||||||
tags += tag
|
|
||||||
else:
|
|
||||||
tags += ' ' + tag
|
|
||||||
|
|
||||||
if tags == DELIMITER:
|
if tags == DELIMITER:
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
if tags[-1] != DELIMITER:
|
|
||||||
tags += DELIMITER
|
|
||||||
|
|
||||||
origTags.extend(tags.strip(DELIMITER).split(DELIMITER))
|
origTags.extend(tags.strip(DELIMITER).split(DELIMITER))
|
||||||
for tag in origTags:
|
for tag in origTags:
|
||||||
if tag not in uniqueTags:
|
if tag not in uniqueTags:
|
||||||
|
2
buku.1
2
buku.1
@ -31,7 +31,7 @@ If the URL contains characters like ';', '&' or brackets they may be interpreted
|
|||||||
URLs are unique in DB. The same URL cannot be added twice. You can update tags and re-fetch title data.
|
URLs are unique in DB. The same URL cannot be added twice. You can update tags and re-fetch title data.
|
||||||
.PP
|
.PP
|
||||||
\fBTags\fR:
|
\fBTags\fR:
|
||||||
- Comma (',') is the tag delimiter in DB. Tags are filtered (for unique tags) and sorted. Hence, any tag cannot have comma(s) in it. In-tag commas are replaced by spaces.
|
- Comma (',') is the tag delimiter in DB. Any tag cannot have comma(s) in it. Tags are filtered (for unique tags) and sorted.
|
||||||
.PP
|
.PP
|
||||||
\fBUpdate\fR operation:
|
\fBUpdate\fR operation:
|
||||||
- If --title, --tag or --comment is passed without argument, clear the corresponding field from DB.
|
- If --title, --tag or --comment is passed without argument, clear the corresponding field from DB.
|
||||||
|
Loading…
Reference in New Issue
Block a user