imdone-core 1.50.2 → 1.50.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/repository.js +40 -10
  2. package/package.json +1 -1
package/lib/repository.js CHANGED
@@ -1573,16 +1573,46 @@ Repository.deserialize = function (repo, cb) {
1573
1573
  }
1574
1574
 
1575
1575
  Repository.regexQuery = function (tasks, queryString) {
1576
- return tasks.map((task) => {
1577
- const match = task.content.match(new RegExp(tools.escapeRegExp(queryString), 'i'))
1578
- task.match = match
1579
- if (match && queryString.trim() && task.interpretedContent) {
1580
- task.interpretedContent = task.interpretedContent.replace(new RegExp(`(${tools.escapeRegExp(queryString.trim())})`, 'gi'), '==$1==' )
1581
- task.updateDescriptionData()
1582
- }
1583
- return task
1584
- }).filter(({match}) => match)
1585
- }
1576
+ return tasks
1577
+ .map((task) => {
1578
+ const escapedQueryString = tools.escapeRegExp(queryString.trim());
1579
+
1580
+ // Regex to match occurrences not part of a URL and not already surrounded by `==`
1581
+ const regex = new RegExp(
1582
+ `(?<!https?:\\/\\/[^\\s]*?)\\b${escapedQueryString}\\b(?![^\\s]*\\/)(?<!==)(?!==)`,
1583
+ 'gi'
1584
+ );
1585
+
1586
+ // Regex to detect Markdown links `[title](url)` where `queryString` is in title or URL
1587
+ const markdownLinkRegex = new RegExp(
1588
+ `\\[([^\\]]*${escapedQueryString}[^\\]]*)\\]\\(([^)]+${escapedQueryString}[^)]*)\\)`,
1589
+ 'gi'
1590
+ );
1591
+
1592
+ let match = task.content.match(regex) || task.content.match(markdownLinkRegex);
1593
+ task.match = match;
1594
+
1595
+ if (match && queryString.trim() && task.interpretedContent) {
1596
+ // Replace standalone occurrences
1597
+ task.interpretedContent = task.interpretedContent.replace(
1598
+ regex,
1599
+ '==$&=='
1600
+ );
1601
+
1602
+ // Replace Markdown links where queryString is in title or URL
1603
+ task.interpretedContent = task.interpretedContent.replace(
1604
+ markdownLinkRegex,
1605
+ (match) => `==${match}==`
1606
+ );
1607
+
1608
+ task.updateDescriptionData();
1609
+ }
1610
+
1611
+ return task;
1612
+ })
1613
+ .filter(({ match }) => match);
1614
+ };
1615
+
1586
1616
 
1587
1617
  Repository.parseSortFromQueryString = function (queryString) {
1588
1618
  const sort = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "1.50.2",
3
+ "version": "1.50.3",
4
4
  "description": "imdone-core",
5
5
  "main": "index.js",
6
6
  "scripts": {