remark-custom-tasks
Version:
remark plugin for custom task markers in markdown lists
102 lines (74 loc) • 1.74 kB
Markdown
A [remark](https://github.com/remarkjs/remark) plugin that adds support for custom task markers in markdown lists.
```bash
npm install remark-custom-tasks
```
```js
import { remark } from 'remark'
import remarkCustomTasks from 'remark-custom-tasks'
const markdown = `
- Regular list item
- [q] Question to answer
- [x] Completed task
- [ ] Open task
- [D] Decision to make
`
async function process() {
const file = await remark()
.use(remarkCustomTasks)
.process(markdown)
console.log(String(file))
}
process()
```
This plugin recognizes list items with markers in square brackets:
- `[q]` - Question
- `[x]` - Completed task
- `[ ]` - Open task
- `[D]` - Decision
- Any other marker between `[` and `]`
This plugin adds `marker` and `taskContent` properties to list item nodes in the mdast that have custom markers.
Example:
```js
// Input: - [q] What is a SPA?
// Output AST node:
{
type: 'listItem',
marker: 'q',
taskContent: 'What is a SPA?'
children: [
{
type: 'paragraph',
children: [
{
type: 'text',
value: '[q] What is a SPA?'
}
]
}
]
}
```
Run the automated tests:
```bash
npm test
```
This will run all unit tests in the `test` directory.
For manual testing with a sample markdown input:
```bash
npm run demo
```
You can also test with your own Markdown files using remark-cli:
```bash
./node_modules/.bin/remark path/to/your/file.md --tree-out --use=./index.js
./node_modules/.bin/remark path/to/your/file.md --tree-out --use=remark-custom-tasks
```
MIT