0.0.22 • Published 10 years ago

mpm.shortcode v0.0.22

Weekly downloads
1
License
-
Repository
github
Last release
10 years ago

mpm.shortcode

author mparaiso mparaiso@online.fr

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 :

are valid shortcodes.

####LIMITATIONS

  • shortcodes cannot be nested ( FOR NOW )
0.0.22

10 years ago

0.0.21

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago