https://github.com/masylum/minimarkdown
An easy to extend parser for a subset of markdown
https://github.com/masylum/minimarkdown
Last synced: 11 months ago
JSON representation
An easy to extend parser for a subset of markdown
- Host: GitHub
- URL: https://github.com/masylum/minimarkdown
- Owner: masylum
- License: mit
- Created: 2015-09-28T16:32:01.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-12T13:31:54.000Z (over 10 years ago)
- Last Synced: 2025-03-15T23:44:33.771Z (over 1 year ago)
- Language: JavaScript
- Size: 190 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# miniMarkdown

^ Markdown
An easy to extend parser for a subset of markdown.
[](https://travis-ci.org/masylum/miniMarkdown)
[](https://github.com/feross/standard)
## Markdown support
miniMarkdown supports:
- ```` ```pre``` ````
- `` `code` ``
- ` _Italics_ `
- ` *Bold* `
- ` ~Strike~ `
You can easily add more grammar to make your own extensions
## API
To run with the default grammar:
```js
let miniMarkdown = require('miniMarkdown');
let text = 'this *is* an _example_';
let grammar = miniMarkdown.DEFAULT_GRAMMAR;
let tokenizer = new miniMarkdown.Tokenizer(text, grammar);
tokenizer.run();
=> [
{type: 'word', text: 'this '}
, {type: 'bold', children: [{type: 'word', text: 'is'}]}
, {type: 'word', text: ' an '}
, {type: 'italic', children: [{type: 'word', text: 'example'}]}
]
```
If you are interested into adding more grammar you can also do so!
`TokenType` offers you an API to define grammar:
- `start`: The string that defines the beggining of a token.
- `end`: The string that defines the ending of a token.
- `surround`: When both start and end delimiters are the same you can use this instead.
- `grammar`: If you want a different grammar for a given token.
- `constraint`: If you want to validate whether the token is valid before pushing it to the tree.
You can see grammar examples on the `spec/grammar_spec.js` test file.
## TEST
To test just run `npm test`