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

Allow users to define the date template #50

Merged
merged 3 commits into from
Apr 2, 2023
Merged
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
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