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

Colorize key:date value as a date #53

Open
wants to merge 17 commits into
base: master
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
22 changes: 18 additions & 4 deletions grammars/todotxt.cson
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
'match': '^\\([A-Z]\\)'
'name': 'constant.language.todotxt.priority'
}
{
'match': 'due:\\d{4}-\\d{2}-\\d{2}'
'name': 'constant.language.todotxt.due'
}
{
'match': '(\\S+)(:)(\\d{4}-\\d{2}-\\d{2})'
'captures': {
'1': {
'name': 'property.language.todotxt.key'
}
'2': {
'name': 'punctuation.language.todotxt.pair'
}
'3': {
'name': 'constant.language.todotxt.date'
}
}
}
{
'match': '(\\S+)(:)(\\S+)'
'captures': {
Expand All @@ -25,10 +43,6 @@
'match': '(?:^|(?<=^\\([A-Z]\\)\\s))\\d{4}-\\d{2}-\\d{2}'
'name': 'constant.language.todotxt.date'
}
{
'match': 'due:\\d{4}-\\d{2}-\\d{2}'
'name': 'constant.language.todotxt.due'
}
{
'match': ' (\\@\\S+)'
'captures': {
Expand Down
17 changes: 17 additions & 0 deletions spec/grammars-todotxt-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ describe("todo.txt grammar", () => {
expect(matches.length).toEqual(0);
});

it("matches due:yyyy-mm-dd properties correctly", () => {
let {tokens} = grammar.tokenizeLine("Syntax colorisation for due:2018-10-23 metadata");
let [keyValueToken] = tokens.filter((token) => { return token.value == "due:2018-10-23"; });
expect(keyValueToken.scopes).toEqual(["text.todotxt", "constant.language.todotxt.due"])
});

it("matches key:value properties correctly", () => {
let {tokens} = grammar.tokenizeLine("Syntax colorisation for key:value pairs");
let [keyToken] = tokens.filter((token) => { return token.value == "key"; });
Expand All @@ -148,6 +154,17 @@ describe("todo.txt grammar", () => {
expect(valueToken.scopes).toEqual(["text.todotxt", "value.language.todotxt.value"])
});

it("matches key:yyyy-mm-dd correctly", () => {
let {tokens} = grammar.tokenizeLine("(B) 2017-09-20 Syntax highlighting for key:2018-10-23 metadata +LanguageTodotxt +110");
console.log(JSON.stringify(tokens))
let [keyToken] = tokens.filter((token) => { return token.value == "key"; });
expect(keyToken.scopes).toEqual(["text.todotxt", "property.language.todotxt.key"])
let [colonToken] = tokens.filter((token) => { return token.value == ":"; });
expect(colonToken.scopes).toEqual(["text.todotxt", "punctuation.language.todotxt.pair"])
let [valueToken] = tokens.filter((token) => { return token.value == "2018-10-23"; });
expect(valueToken.scopes).toEqual(["text.todotxt", "constant.language.todotxt.date"])
});

it("matches create date without priority", () => {
let {tokens} = grammar.tokenizeLine("2018-02-27 match create date without priority");
console.log(JSON.stringify(tokens))
Expand Down