Download raw (1.7 KB)
(function (extension) { 'use strict'; // UML - Universal Module Loader // This enables the extension to be loaded in different environments if (typeof showdown !== 'undefined') { // global (browser or nodejs global) extension(showdown); } else if (typeof define === 'function' && define.amd) { // AMD define(['showdown'], extension); } else if (typeof exports === 'object') { // Node, CommonJS-like module.exports = extension(require('showdown')); } else { // showdown was not found so we throw throw Error('Could not find showdown library'); } }(function (showdown) { 'use strict'; // Initialize a showdown converter to be used in the extension core var converter = new showdown.Converter(); // The following method will register the extension with showdown showdown.extension('classify', function () { var x = 0; var ext = { type: 'lang', filter: function(text, converter, options) { var classNAMES = text.match(/\[(.*)--]/g), newText = text; if ((x < 3) && (classNAMES != null)) { ++x; for (var i = 0; i < classNAMES.length; i++) { var classNAME = classNAMES[i].match(/\[(.*)--]/)[1]; if (classNAME != '') { var regex = new RegExp("\\["+classNAME+"--]([\\s\\S]*)\\[--"+classNAME+"]"), textSPLIT = newText.match(regex); if (textSPLIT != null) { var textSNIPPET = textSPLIT[1], html = converter.makeHtml(textSNIPPET); newText = newText.replace(regex, '<div class="'+classNAME+'">'+html+'</div>'); } } } } x = 0; return newText; } }; return [ext]; }); }));