Skip to content

Commit 6baeaed

Browse files
committed
Allows for sub-items below a task re #19
1 parent 4e4367f commit 6baeaed

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

src/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ export const DATE_REGEX = /(?<target>{{date:?(?<date>[^}]*)}})/g;
33

44
export const DAY_PLANNER_FILENAME = 'Day Planner-{{date}}.md';
55

6-
//https://regex101.com/r/FClNLv/2
6+
//https://regex101.com/r/VAxRnc/3
77
export const PLAN_PARSER_REGEX =
8-
/^((-?[\s]*\[?(?<completion>[x ]*)\])?(\d.)?\s*?(?<hours>\d{1,2}):(?<minutes>\d{2})\s)((?<break>BREAK)|(?<end>END|finish)|((?<text>.*)))$/gmi;
8+
/^(((-?[\s]*\[?(?<completion>[x ]*)\])?(\d.)?\s*?(?<hours>\d{1,2}):(?<minutes>\d{2})\s)((?<break>BREAK)|(?<end>END|finish)|((?<text>.*))))|((?<unmatched>[ \t]*- .*))$/gmi;
99

1010
export const DAY_PLANNER_DEFAULT_CONTENT =
1111
`## Day Planner

src/mermaid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class PlannerMermaid {
2222
}
2323

2424
generate(planSummary: PlanSummaryData): string {
25-
const {tasks, breaks} = this.generateEntries(planSummary.items);
25+
const {tasks, breaks} = this.generateEntries(planSummary.validItems());
2626
return this.mermaidTemplate(tasks, breaks);
2727
}
2828

src/parser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Vault } from 'obsidian';
2+
import { pid } from 'process';
23
import { PLAN_PARSER_REGEX } from './constants';
34
import { PlanItem, PlanSummaryData } from './plan-data';
45

@@ -31,6 +32,11 @@ export default class Parser {
3132
private transform(regexMatches: RegExpExecArray[]): PlanItem[]{
3233
const results = regexMatches.map((value:RegExpExecArray, index) => {
3334
try {
35+
const isUnmatched = value.groups.unmatched !== undefined;
36+
if(isUnmatched) {
37+
const unMatchedText = value[0];
38+
return new PlanItem(index, value.index, false, false, false, true, undefined, undefined, unMatchedText, unMatchedText)
39+
}
3440
const isCompleted = this.matchValue(value.groups.completion, 'x');
3541
const isBreak = this.matchValue(value.groups.break, 'break');
3642
const isEnd = this.matchValue(value.groups.end, 'end');
@@ -44,6 +50,7 @@ export default class Parser {
4450
isCompleted,
4551
isBreak,
4652
isEnd,
53+
false,
4754
time,
4855
`${value.groups.hours.padStart(2, '0')}:${value.groups.minutes}`,
4956
value.groups.text?.trim(),

src/plan-data.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ export class PlanSummaryData {
1616
calculate(): void {
1717
try {
1818
const now = new Date();
19-
if(this.items.length === 0){
19+
const validItems = this.validItems();
20+
if(validItems.length === 0){
2021
this.empty = true;
2122
return;
2223
}
23-
this.items.forEach((item, i) => {
24-
const next = this.items[i+1];
25-
if(item.time < now && (item.isEnd || (next && now < next.time))){
24+
validItems.forEach((item, i) => {
25+
const next = validItems[i+1];
26+
if(item.time < now && (item.isEnd || (next && now < next.time))) {
2627
this.current = item;
2728
this.next = item.isEnd ? null : next;
28-
} else if(item.time < now){
29+
} else if(item.time < now) {
2930
item.isPast = true;
3031
this.past.push(item);
3132
}
@@ -34,6 +35,10 @@ export class PlanSummaryData {
3435
console.log(error)
3536
}
3637
}
38+
39+
validItems(): PlanItem[] {
40+
return this.items.filter(item => !item.isUnMatched);
41+
}
3742
}
3843

3944
export class PlanItem {
@@ -44,18 +49,20 @@ export class PlanItem {
4449
isPast: boolean;
4550
isBreak: boolean;
4651
isEnd: boolean;
52+
isUnMatched: boolean;
4753
time: Date;
4854
rawTime: string;
4955
text: string;
5056
raw: string;
51-
57+
5258
constructor(matchIndex: number, charIndex: number, isCompleted: boolean,
53-
isBreak: boolean, isEnd: boolean, time: Date, rawTime:string, text: string, raw: string){
59+
isBreak: boolean, isEnd: boolean, isUnMatched: boolean, time: Date, rawTime:string, text: string, raw: string){
5460
this.matchIndex = matchIndex;
5561
this.charIndex = charIndex;
5662
this.isCompleted = isCompleted;
5763
this.isBreak = isBreak;
5864
this.isEnd = isEnd;
65+
this.isUnMatched = isUnMatched;
5966
this.time = time;
6067
this.rawTime = rawTime;
6168
this.text = text;

src/planner-md.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export default class PlannerMarkdown {
6767
let result = '';
6868
if(item === planSummary.current){
6969
result = item.isEnd ? this.updateItemCompletion(item, true) : this.currentItemText(planSummary);
70+
} else if(item.isUnMatched) {
71+
result = item.raw;
7072
} else {
7173
result = this.updateItemCompletion(item, item.isPast);
7274
}
@@ -120,7 +122,7 @@ export default class PlannerMarkdown {
120122
const next = planSummary.next;
121123

122124
const progressMarkdown = `> ||${current.rawTime}||${this.progress.progressMarkdown(current, next)}||${next.rawTime}||`;
123-
let replacementItem = `\n**Current Task**\n${this.updateItemCompletion(current, false)}\n\n${progressMarkdown}\n`;
125+
let replacementItem = `\n**Current Task**\n\n${progressMarkdown}\n\n${this.updateItemCompletion(current, false)}`;
124126
return replacementItem;
125127
} catch (error) {
126128
console.log(error)

0 commit comments

Comments
 (0)