https://github.com/jonschlinkert/markdown-symbols
Easily add and create custom symbols to use in markdown, and then compile them to HTML.
https://github.com/jonschlinkert/markdown-symbols
markdown
Last synced: 13 days ago
JSON representation
Easily add and create custom symbols to use in markdown, and then compile them to HTML.
- Host: GitHub
- URL: https://github.com/jonschlinkert/markdown-symbols
- Owner: jonschlinkert
- License: mit
- Created: 2014-02-21T19:08:40.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-05-27T11:22:32.000Z (over 11 years ago)
- Last Synced: 2025-05-05T21:51:07.867Z (6 months ago)
- Topics: markdown
- Language: JavaScript
- Homepage: https://github.com/jonschlinkert
- Size: 129 KB
- Stars: 19
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# markdown-symbols
> Easily add and create custom symbols to use in markdown, and then compile them to HTML.
If you find a bug or have a feature request, [please create an issue](https://github.com/jonschlinkert/markdown-symbols/issues).
Inspired by [@Vinz243](https://github.com/Vinz243) from [this issue on marked-extras](https://github.com/assemble/marked-extras/issues/3).
## Install
Install with [npm](npmjs.org):
```bash
npm i markdown-symbols --save
```
## Usage
```js
var symbols = require('markdown-symbols');
symbols.process( String );
```
## Add Custom Symbols
> An array of replacement patterns for custom symbols can be passed as a second parameter
```js
symbols.process( String, patterns );
```
Replacement patterns follow this format:
```js
var patterns = [
{
pattern: /foo/, // the pattern to replace
replacement: 'bar' // the replacement. can be a string or a function.
}
];
```
### Example
This is the pattern and replacement used to for alerts:
```js
var patterns = [
{
pattern: symbols.makeDelims(['!!', '!!']),
replacement: function (match, inner) {
var arr = inner.split('|');
var text = arr[0];
var modifier = arr[1] ? ' alert-' + arr[1] : '';
return '' + text + '';
}
}
];
```
Take a look at [index.js](./index.js) to see how the others are created.
### .makeDelims()
For patterns, the `makeDelims` utility method is a convenience for more easily creating custom symbols:
```js
symbols.makeDelims(['!!', '!!'])
```
The [delims](https://github.com/jonschlinkert/delims) library is used to create delimiters, visit that project to learn about usage and available options.
## Examples
To build the examples, run `npm i && node examples/example`
### Labels
```
||This is a label!||
||This is a label!|warning||
||This is a label!|success||
```
### Spoiler
```
> and captcha protected spoilers:
\{{Simple spoiler|info}}
!\{{Write me at |info}}
```
### Progress bars
```
=====0%=====
=====10%|error=====
=====40%|warning=====
=====80%|success=====
```
### Glyphicons
```
::|search::
```
## Badges
```
[[42]]
[[42|danger]]
```
## Jumbotrons
```
////
Hello, world|small
////
```
## Alerts
```
!!New update released! !!
!!New update released!|info!!
```
## Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license