mpm.shortcode
v0.0.22
Published
shortcode api for nodejs, nano templating library
Downloads
2
Readme
mpm.shortcode
author mparaiso [email protected]
license LGPL
nano templating for nodejs and the browser.
ShortCode allows javascript developpers to use a nano templating engine in their application.
In a cms for instance , a content field can support shortcodes and allow users to write complex content without knowing HTML ( integrate a video player in a page for instance), and without the app allowing the user to directly write HTML tags.
####INSTALLATION npm install mpm.shorcode
####USAGE
var shortcode = require('mpm.shortcode');
// you can pass a context to the shortcode,
// which will be avaiable to each shortcode.
context = { name:'foo'};
var myShortCodes = new shortcode.ShortCode(context);
// let's define our first shortcode , that yields a video tag
var myShortCodes.add('video',function(attributes,content,context){
return "<video src='"+attributes.src+"' >"+content+"</video>";
});
//debug mode
myShortCodes.setDebug(true);
//a string will get evaluated
var string = "[video src='video.mp4']No video Support[/video]"
var result = myShortCodes.parse(string);
console.log(result)
/**
* will yield :
* <video src='video.mp4'>No video Support</video>
*/
Shortcodes can have closing tags or not :
- [foo bar='baz'/]
- [bar foo='fizz']
- [baz fizz='foo'] content [/baz]
are valid shortcodes.
####LIMITATIONS
- shortcodes cannot be nested ( FOR NOW )