Skip to content

Commit

Permalink
Merge pull request #196 from Laharah/inlineDv
Browse files Browse the repository at this point in the history
Support for inline dataview fields
  • Loading branch information
lazyguru authored Nov 17, 2023
2 parents 4b37f3a + 92a9018 commit e1ffed2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
20 changes: 20 additions & 0 deletions examples/TestEmoji.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

```tracker
searchType: dvfield
searchTarget: Physical
folder: diary
startDate: 2023-06-04
endDate: 2023-06-11
textValueMap:
😀: 5
🙂: 4
😐: 3
🙁: 2
😞: 1
datasetName: 🚹 Physical
line:
lineColor: orange
lineWidth: 3
showLegend: true
legendPosition: right
```
15 changes: 15 additions & 0 deletions examples/TestInSentenceFields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

```tracker
searchType: frontmatter, dvField
searchTarget: date, count
xDataset: 0
folder: "data"
bullet:
title: Total Counts
value: "{{sum()}}"
range: 1,5,10,20
rangeColor: darkRed, lightBlue, lightGreen, blue
showMarker: true
markerValue: 2
markerColor: red
```
9 changes: 9 additions & 0 deletions examples/data/In-Sentence-Fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
date: 2021-01-05
---

I am [count:: 1] inline
So am (count::2) I
count:: 3
| count:: 4 |
|count:: 5|
1 change: 1 addition & 0 deletions examples/diary/2023-06-05.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Physical:: 😐
1 change: 1 addition & 0 deletions examples/diary/2023-06-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Physical:: 😐
1 change: 1 addition & 0 deletions examples/diary/2023-06-07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Physical:: 😀
1 change: 1 addition & 0 deletions examples/diary/2023-06-08.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Physical:: 😞
24 changes: 15 additions & 9 deletions src/collecting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import * as helper from "./helper";
import { Moment } from "moment";

// ref: https://www.rapidtables.com/code/text/unicode-characters.html
const CurrencyCodes = "\u0024\u20AC\u00A3\u00A5\u00A2\u20B9\u20A8\u20B1\u20A9\u0E3F\u20AB\u20AA";
const CurrencyCodes =
"\u0024\u20AC\u00A3\u00A5\u00A2\u20B9\u20A8\u20B1\u20A9\u0E3F\u20AB\u20AA";
const AlphabetCodes = "\u03B1-\u03C9\u0391-\u03A9";
const IntellectualPropertyCodes = "\u00A9\u00AE\u2117\u2122\u2120";
const CJKCodes = "\u4E00-\u9FFF\u3400-\u4DBF\u3000\u3001-\u303F";
const WordCharacters = "\\w" + CurrencyCodes + AlphabetCodes + IntellectualPropertyCodes + CJKCodes;
const WordCharacters =
"\\w" +
CurrencyCodes +
AlphabetCodes +
IntellectualPropertyCodes +
CJKCodes;

// fileBaseName is a string contains dateFormat only
export function getDateFromFilename(
Expand Down Expand Up @@ -333,7 +339,7 @@ function extractDataUsingRegexWithMultipleValues(
): boolean {
// console.log("extractDataUsingRegexWithMultipleValues");

let regex = new RegExp(strRegex, "gm");
let regex = new RegExp(strRegex, "gmu");
let match;
let measure = 0.0;
let extracted = false;
Expand Down Expand Up @@ -512,9 +518,9 @@ export function collectDataFromFrontmatterKey(
// console.log(retParse);
if (retParse.value === null) {
// Try parsing as a boolean: true means 1, false means 0.
if (deepValue === 'true' || deepValue === 'false') {
if (deepValue === "true" || deepValue === "false") {
retParse.type = ValueType.Number;
retParse.value = deepValue === 'true' ? 1 : 0;
retParse.value = deepValue === "true" ? 1 : 0;
}
}
if (retParse.value !== null) {
Expand Down Expand Up @@ -798,13 +804,13 @@ export function collectDataFromDvField(

// Test this in Regex101
// remember '\s' includes new line
// (^| |\t)\*{0,2}dvTarget\*{0,2}(::[ |\t]*(?<value>[\d\.\/\-\w,@; \t:]*))(\r?\n|\r|$)
// (^| |\t|\|)(\[|\()?\*{0,2}dvTarget\*{0,2}(::[ |\t]*(?<value>[\d\.\/\-\w,@; \t:]*)(\]|\))?)
let strRegex =
"(^| |\\t)\\*{0,2}" +
String.raw`(^| |\t|\|)(\[|\()?\*{0,2}` +
dvTarget +
"\\*{0,2}(::[ |\\t]*(?<value>[\\d\\.\\/\\-,@; \\t:" +
String.raw`\*{0,2}(::[ |\t]*(?<value>[\p{ExtPict}\d\.\/\-\w,@; \t:` +
WordCharacters +
"]*))(\\r\\?\\n|\\r|$)";
String.raw`]*)(\]|\))?)`;
// console.log(strRegex);

return extractDataUsingRegexWithMultipleValues(
Expand Down

0 comments on commit e1ffed2

Please sign in to comment.