Skip to content

Commit

Permalink
Allow users to define the date template (#50)
Browse files Browse the repository at this point in the history
* Allow users to define decoration for date

* Add readme description

* Adjust config description

---------

Co-authored-by: Philipp Kief <philipp.kief@gmx.de>
  • Loading branch information
m-paternostro and PKief authored Apr 2, 2023
1 parent edbead1 commit 6b29bd5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ If dates are enabled, they can be formatted with the following user setting:

It makes use of the JavaScript library [moment.js](https://momentjs.com/docs/#/parsing/string-format/) which means that the date format patterns can be found there.

In addition the syntax around in which the date is placed can be defined via template. `{date}` will be replaced by the actual date value:

```json
"markdown-checkbox.dateTemplate": "({date})"
```

Preview:

- [x] ~~_sample with date_~~ (2017-11-23)

### Specify language IDs

Besides markdown, this extension can also be used for other languages in VS Code. The language IDs can be specified in the user settings like this:
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@
"type": "string",
"default": "YYYY-MM-DD",
"description": "Format date"
},
"markdown-checkbox.dateTemplate": {
"type": "string",
"default": "[{date}]",
"markdownDescription": "The date template `{date}` is replaced by the actual date."
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/toggleCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ const markField = (
newText = `~~${newText}~~`;
}
if (dateWhenChecked) {
newText = `${newText} [${moment(new Date()).format(
dateFormat
)}]${whitespace}`;
const date = moment(new Date()).format(dateFormat);
const decoratedDate = helpers
.getConfig<string>('dateTemplate')
.replace('{date}', date);
newText = `${newText} ${decoratedDate}${whitespace}`;
}

editBuilder.replace(
Expand Down

0 comments on commit 6b29bd5

Please sign in to comment.