mirror of
https://github.com/tbabej/taskwiki.git
synced 2025-08-18 12:23:06 +02:00
vwtags: Viewports/presets shown using their name only
In other words hide the parts behind `|`. Handle vimwiki links correctly.
This commit is contained in:
parent
91f98d54b3
commit
07dc2b8ceb
3 changed files with 62 additions and 26 deletions
|
@ -1,35 +1,43 @@
|
|||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
rx_default_media = r"^\s*(={1,6})([^=].*[^=])\1\s*$"
|
||||
rx_markdown = r"^\s*(#{1,6})([^#].*)$"
|
||||
if __name__ == '__main__':
|
||||
path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
sys.path.insert(0, path)
|
||||
|
||||
from taskwiki import regexp
|
||||
|
||||
|
||||
def match_header(line, syntax):
|
||||
m = re.search(regexp.VIEWPORT[syntax], line)
|
||||
if m:
|
||||
return m
|
||||
|
||||
m = re.search(regexp.PRESET[syntax], line)
|
||||
if m:
|
||||
return m
|
||||
|
||||
m = re.search(regexp.HEADER[syntax], line)
|
||||
if m:
|
||||
return m
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def process(file_content, filename, syntax):
|
||||
if syntax in ("default", "media"):
|
||||
rx_header = re.compile(rx_default_media)
|
||||
elif syntax == "markdown":
|
||||
rx_header = re.compile(rx_markdown)
|
||||
else:
|
||||
rx_header = re.compile(rx_default_media + "|" + rx_markdown)
|
||||
|
||||
state = [""]*6
|
||||
for lnum, line in enumerate(file_content):
|
||||
|
||||
match_header = rx_header.match(line)
|
||||
|
||||
if not match_header:
|
||||
m = match_header(line, syntax)
|
||||
if not m:
|
||||
continue
|
||||
|
||||
match_lvl = match_header.group(1) or match_header.group(3)
|
||||
match_tag = match_header.group(2) or match_header.group(4)
|
||||
|
||||
cur_lvl = len(match_lvl)
|
||||
cur_tag = match_tag.strip()
|
||||
cur_searchterm = "^" + match_header.group(0).rstrip("\r\n") + "$"
|
||||
cur_lvl = len(m.group('header_start'))
|
||||
cur_tag = m.group('name').strip()
|
||||
cur_searchterm = "^" + m.group(0).rstrip("\r\n") + "$"
|
||||
cur_kind = "h"
|
||||
|
||||
state[cur_lvl-1] = cur_tag
|
||||
|
|
|
@ -45,7 +45,7 @@ VIEWPORT = {
|
|||
'default':
|
||||
re.compile(
|
||||
r'^' # Starts at the begging of the line
|
||||
r'[=]+' # Heading begging
|
||||
r'(?P<header_start>[=]+)' # Heading begging
|
||||
r'(?P<name>[^=\|\[\{]*)' # Name of the viewport, all before the | sign
|
||||
# Cannot include '[', '=', '|', and '{'
|
||||
r'\|' # Bar
|
||||
|
@ -65,7 +65,7 @@ VIEWPORT = {
|
|||
'markdown':
|
||||
re.compile(
|
||||
r'^' # Starts at the begging of the line
|
||||
r'[#]+' # Heading begging
|
||||
r'(?P<header_start>[#]+)' # Heading begging
|
||||
r'(?P<name>[^#\|\[\{]*)' # Name of the viewport, all before the | sign
|
||||
# Cannot include '[', '#', '|', and '{'
|
||||
r'\|' # Bar
|
||||
|
@ -89,7 +89,7 @@ HEADER = {
|
|||
re.compile(
|
||||
r'^' # Starts at the beginning of the line
|
||||
r'(?P<header_start>[=]+)' # With a positive number of =
|
||||
r'[^=]+' # Character other than =
|
||||
r'(?P<name>[^=]+)' # Character other than =
|
||||
r'[=]+' # Positive number of =, closing the header
|
||||
r'\s*' # Allow trailing whitespace
|
||||
),
|
||||
|
@ -97,7 +97,7 @@ HEADER = {
|
|||
re.compile(
|
||||
r'^' # Starts at the beginning of the line
|
||||
r'(?P<header_start>[#]+)' # With a positive number of #
|
||||
r'[^#]+' # Character other than #
|
||||
r'(?P<name>[^#]+)' # Character other than #
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ PRESET = {
|
|||
re.compile(
|
||||
r'^' # Starts at the beginning of the line
|
||||
r'(?P<header_start>[=]+)' # With a positive number of =
|
||||
r'([^=\|\[\{]*)' # Heading caption, everything up to ||
|
||||
r'(?P<name>[^=\|\[\{]*)' # Heading caption, everything up to ||
|
||||
# Cannot include '[', '=', '|, and '{'
|
||||
r'\|\|' # Delimiter
|
||||
r'(?P<filter>[^=\|]+?)' # Filter preset
|
||||
|
@ -121,7 +121,7 @@ PRESET = {
|
|||
re.compile(
|
||||
r'^' # Starts at the beginning of the line
|
||||
r'(?P<header_start>[#]+)' # With a positive number of #
|
||||
r'([^#\|\[\{]*)' # Heading caption, everything up to ||
|
||||
r'(?P<name>[^#\|\[\{]*)' # Heading caption, everything up to ||
|
||||
# Cannot include '[', '#', '|, and '{'
|
||||
r'\|\|' # Delimiter
|
||||
r'(?P<filter>[^#\|]+?)' # Filter preset
|
||||
|
|
|
@ -65,3 +65,31 @@ class TestTagsBasic(MultiSyntaxTagsTest):
|
|||
re.compile(r"^g file.wiki /.*/;\" h line:7$"),
|
||||
re.compile(r"^h file.wiki /.*/;\" h line:8 header:g$"),
|
||||
]
|
||||
|
||||
|
||||
class TestTagsViewportsPresets(MultiSyntaxTagsTest):
|
||||
wiki_input = """\
|
||||
HEADER1(a)
|
||||
HEADER2(b | +DUETODAY)
|
||||
HEADER2(c || +home)
|
||||
HEADER3(d | +OVERDUE | due:today)
|
||||
"""
|
||||
|
||||
expected_output = [
|
||||
re.compile(r"^a file.wiki /.*/;\" h line:1$"),
|
||||
re.compile(r"^b file.wiki /.*/;\" h line:2 header:a$"),
|
||||
re.compile(r"^c file.wiki /.*/;\" h line:3 header:a$"),
|
||||
re.compile(r"^d file.wiki /.*/;\" h line:4 header:a&&&c$"),
|
||||
]
|
||||
|
||||
|
||||
class TestTagsVimwikiLinks(TagsTest):
|
||||
wiki_input = """\
|
||||
= [[link]] =
|
||||
== [[li|nk]] ==
|
||||
"""
|
||||
|
||||
expected_output = """\
|
||||
[[link]] file.wiki /^= [[link]] =$/;" h line:1
|
||||
[[li|nk]] file.wiki /^== [[li|nk]] ==$/;" h line:2 header:[[link]]
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue