angular-marked
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -205,6 +205,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.angularMarked = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var r = new m.Renderer(); | ||
// override rendered markdown html | ||
// with custom definitions if defined | ||
if (self.renderer) { | ||
var r = new m.Renderer(); | ||
var o = Object.keys(self.renderer); | ||
@@ -216,8 +217,22 @@ var l = o.length; | ||
} | ||
} | ||
// add the new renderer to the options if need be | ||
self.defaults = self.defaults || {}; | ||
self.defaults.renderer = r; | ||
// Customize code and codespan rendering to wrap default or overriden output in a ng-non-bindable span | ||
function wrapNonBindable(string) { | ||
return "<span ng-non-bindable>" + string + "</span>"; | ||
} | ||
var renderCode = r.code.bind(r); | ||
r.code = function (code, lang, escaped) { | ||
return wrapNonBindable(renderCode(code, lang, escaped)); | ||
}; | ||
var renderCodespan = r.codespan.bind(r); | ||
r.codespan = function (code) { | ||
return wrapNonBindable(renderCodespan(code)); | ||
}; | ||
// add the new renderer to the options if need be | ||
self.defaults = self.defaults || {}; | ||
self.defaults.renderer = r; | ||
m.setOptions(self.defaults); | ||
@@ -229,3 +244,3 @@ | ||
// TODO: filter and tests */ | ||
// xTODO: filter and tests */ | ||
// app.filter('marked', ['marked', function(marked) { | ||
@@ -246,4 +261,5 @@ // return marked; | ||
* @param {expression=} opts Hash of options that override defaults. | ||
* @param {boolean=} compile Set to true to to support AngularJS directives inside markdown. | ||
* @param {string=} src Expression evaluating to URL. If the source is a string constant, | ||
* make sure you wrap it in **single** quotes, e.g. `src="'myPartialTemplate.html'"`. | ||
* make sure you wrap it in **single** quotes, e.g. `src="'myPartialTemplate.html'"`. | ||
* | ||
@@ -298,3 +314,3 @@ * @example | ||
.directive('marked', ['marked', '$templateRequest', function (marked, $templateRequest) { | ||
.directive('marked', ['marked', '$templateRequest', '$compile', function (marked, $templateRequest, $compile) { | ||
return { | ||
@@ -306,2 +322,3 @@ restrict: 'AE', | ||
marked: '=', | ||
compile: '@', | ||
src: '=' | ||
@@ -324,4 +341,6 @@ }, | ||
function unindent (text) { | ||
if (!text) return text; | ||
function unindent(text) { | ||
if (!text) { | ||
return text; | ||
} | ||
@@ -334,8 +353,10 @@ var lines = text | ||
var len = lines.length; | ||
var i; | ||
var l, line; | ||
for (var i = 0; i < len; i++) { | ||
line = lines[i]; | ||
l = line.match(/^(\s*)/)[0].length; | ||
if (l === line.length) { continue; } | ||
for (i = 0; i < len; i++) { | ||
var line = lines[i]; | ||
var l = line.match(/^(\s*)/)[0].length; | ||
if (l === line.length) { | ||
continue; | ||
} | ||
min = (l < min || min === null) ? l : min; | ||
@@ -352,5 +373,8 @@ } | ||
function set (text) { | ||
function set(text) { | ||
text = unindent(text || ''); | ||
element.html(marked(text, scope.opts || null)); | ||
if (scope.$eval(attrs.compile)) { | ||
$compile(element.contents())(scope.$parent); | ||
} | ||
} | ||
@@ -357,0 +381,0 @@ } |
@@ -1,1 +0,1 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.angularMarked=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";module.exports="hc.marked";angular.module("hc.marked",[]).provider("marked",function(){var self=this;self.setRenderer=function(opts){this.renderer=opts};self.setOptions=function(opts){this.defaults=opts};self.$get=["$log","$window",function($log,$window){var m;try{m=require("marked")}catch(e){m=$window.marked||marked}if(angular.isUndefined(m)){$log.error("angular-marked Error: marked not loaded. See installation instructions.");return}if(self.renderer){var r=new m.Renderer;var o=Object.keys(self.renderer);var l=o.length;while(l--){r[o[l]]=self.renderer[o[l]]}self.defaults=self.defaults||{};self.defaults.renderer=r}m.setOptions(self.defaults);return m}]}).directive("marked",["marked","$templateRequest",function(marked,$templateRequest){return{restrict:"AE",replace:true,scope:{opts:"=",marked:"=",src:"="},link:function(scope,element,attrs){set(scope.marked||element.text()||"");if(attrs.marked){scope.$watch("marked",set)}if(attrs.src){scope.$watch("src",function(src){$templateRequest(src,true).then(function(response){set(response)})})}function unindent(text){if(!text)return text;var lines=text.replace(/\t/g," ").split(/\r?\n/);var min=null;var len=lines.length;var l,line;for(var i=0;i<len;i++){line=lines[i];l=line.match(/^(\s*)/)[0].length;if(l===line.length){continue}min=l<min||min===null?l:min}if(min!==null&&min>0){for(i=0;i<len;i++){lines[i]=lines[i].substr(min)}}return lines.join("\n")}function set(text){text=unindent(text||"");element.html(marked(text,scope.opts||null))}}}}])},{marked:"marked"}]},{},[1])(1)}); | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.angularMarked=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";module.exports="hc.marked";angular.module("hc.marked",[]).provider("marked",function(){var self=this;self.setRenderer=function(opts){this.renderer=opts};self.setOptions=function(opts){this.defaults=opts};self.$get=["$log","$window",function($log,$window){var m;try{m=require("marked")}catch(e){m=$window.marked||marked}if(angular.isUndefined(m)){$log.error("angular-marked Error: marked not loaded. See installation instructions.");return}var r=new m.Renderer;if(self.renderer){var o=Object.keys(self.renderer);var l=o.length;while(l--){r[o[l]]=self.renderer[o[l]]}}function wrapNonBindable(string){return"<span ng-non-bindable>"+string+"</span>"}var renderCode=r.code.bind(r);r.code=function(code,lang,escaped){return wrapNonBindable(renderCode(code,lang,escaped))};var renderCodespan=r.codespan.bind(r);r.codespan=function(code){return wrapNonBindable(renderCodespan(code))};self.defaults=self.defaults||{};self.defaults.renderer=r;m.setOptions(self.defaults);return m}]}).directive("marked",["marked","$templateRequest","$compile",function(marked,$templateRequest,$compile){return{restrict:"AE",replace:true,scope:{opts:"=",marked:"=",compile:"@",src:"="},link:function(scope,element,attrs){set(scope.marked||element.text()||"");if(attrs.marked){scope.$watch("marked",set)}if(attrs.src){scope.$watch("src",function(src){$templateRequest(src,true).then(function(response){set(response)})})}function unindent(text){if(!text){return text}var lines=text.replace(/\t/g," ").split(/\r?\n/);var min=null;var len=lines.length;var i;for(i=0;i<len;i++){var line=lines[i];var l=line.match(/^(\s*)/)[0].length;if(l===line.length){continue}min=l<min||min===null?l:min}if(min!==null&&min>0){for(i=0;i<len;i++){lines[i]=lines[i].substr(min)}}return lines.join("\n")}function set(text){text=unindent(text||"");element.html(marked(text,scope.opts||null));if(scope.$eval(attrs.compile)){$compile(element.contents())(scope.$parent)}}}}}])},{marked:"marked"}]},{},[1])(1)}); |
@@ -204,6 +204,7 @@ /* | ||
var r = new m.Renderer(); | ||
// override rendered markdown html | ||
// with custom definitions if defined | ||
if (self.renderer) { | ||
var r = new m.Renderer(); | ||
var o = Object.keys(self.renderer); | ||
@@ -215,8 +216,22 @@ var l = o.length; | ||
} | ||
} | ||
// add the new renderer to the options if need be | ||
self.defaults = self.defaults || {}; | ||
self.defaults.renderer = r; | ||
// Customize code and codespan rendering to wrap default or overriden output in a ng-non-bindable span | ||
function wrapNonBindable(string) { | ||
return "<span ng-non-bindable>" + string + "</span>"; | ||
} | ||
var renderCode = r.code.bind(r); | ||
r.code = function (code, lang, escaped) { | ||
return wrapNonBindable(renderCode(code, lang, escaped)); | ||
}; | ||
var renderCodespan = r.codespan.bind(r); | ||
r.codespan = function (code) { | ||
return wrapNonBindable(renderCodespan(code)); | ||
}; | ||
// add the new renderer to the options if need be | ||
self.defaults = self.defaults || {}; | ||
self.defaults.renderer = r; | ||
m.setOptions(self.defaults); | ||
@@ -228,3 +243,3 @@ | ||
// TODO: filter and tests */ | ||
// xTODO: filter and tests */ | ||
// app.filter('marked', ['marked', function(marked) { | ||
@@ -245,4 +260,5 @@ // return marked; | ||
* @param {expression=} opts Hash of options that override defaults. | ||
* @param {boolean=} compile Set to true to to support AngularJS directives inside markdown. | ||
* @param {string=} src Expression evaluating to URL. If the source is a string constant, | ||
* make sure you wrap it in **single** quotes, e.g. `src="'myPartialTemplate.html'"`. | ||
* make sure you wrap it in **single** quotes, e.g. `src="'myPartialTemplate.html'"`. | ||
* | ||
@@ -297,3 +313,3 @@ * @example | ||
.directive('marked', ['marked', '$templateRequest', function (marked, $templateRequest) { | ||
.directive('marked', ['marked', '$templateRequest', '$compile', function (marked, $templateRequest, $compile) { | ||
return { | ||
@@ -305,2 +321,3 @@ restrict: 'AE', | ||
marked: '=', | ||
compile: '@', | ||
src: '=' | ||
@@ -323,4 +340,6 @@ }, | ||
function unindent (text) { | ||
if (!text) { return text; } | ||
function unindent(text) { | ||
if (!text) { | ||
return text; | ||
} | ||
@@ -333,7 +352,10 @@ var lines = text | ||
var len = lines.length; | ||
var i; | ||
for (var i = 0; i < len; i++) { | ||
for (i = 0; i < len; i++) { | ||
var line = lines[i]; | ||
var l = line.match(/^(\s*)/)[0].length; | ||
if (l === line.length) { continue; } | ||
if (l === line.length) { | ||
continue; | ||
} | ||
min = (l < min || min === null) ? l : min; | ||
@@ -350,5 +372,8 @@ } | ||
function set (text) { | ||
function set(text) { | ||
text = unindent(text || ''); | ||
element.html(marked(text, scope.opts || null)); | ||
if (scope.$eval(attrs.compile)) { | ||
$compile(element.contents())(scope.$parent); | ||
} | ||
} | ||
@@ -355,0 +380,0 @@ } |
{ | ||
"name": "angular-marked", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "AngularJS Markdown using marked.", | ||
@@ -14,12 +14,14 @@ "main": "lib/angular-marked.js", | ||
"browserify": "^12.0.1", | ||
"grunt": "^0.4.4", | ||
"grunt": "^0.4.5", | ||
"grunt-gh-pages": "^0.9.1", | ||
"grunt-ngdocs": "^0.2.5", | ||
"jasmine-core": "^2.4.1", | ||
"karma": "^0.13.15", | ||
"karma-chrome-launcher": "^0.1.3", | ||
"karma-jasmine": "^0.1.5", | ||
"karma-phantomjs-launcher": "^0.1.4", | ||
"karma-chrome-launcher": "^0.2.3", | ||
"karma-jasmine": "^0.3.8", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
"load-grunt-tasks": "^0.4.0", | ||
"semistandard": "^7.0.2", | ||
"uglifyjs": "^2.4.10" | ||
"phantomjs-prebuilt": "^2.1.0", | ||
"uglifyjs": "^2.4.10", | ||
"xo": "^0.14.0" | ||
}, | ||
@@ -32,3 +34,3 @@ "scripts": { | ||
"build": "npm run compile && npm run ngdocs", | ||
"lint": "semistandard lib/*.js test/**/*.js", | ||
"lint": "xo lib/*.js test/**/*.js", | ||
"test": "npm run compile && karma start --single-run --browsers PhantomJS", | ||
@@ -50,3 +52,9 @@ "check": "npm run lint && npm run test" | ||
}, | ||
"homepage": "https://github.com/Hypercubed/angular-marked" | ||
"homepage": "https://github.com/Hypercubed/angular-marked", | ||
"xo": { | ||
"space": 2, | ||
"envs": [ | ||
"browser" | ||
] | ||
} | ||
} |
@@ -127,2 +127,27 @@ # angular-marked | ||
Use ```compile``` attribute to support AngularJS directives inside markdown. | ||
```html | ||
<script type="text/ng-template" id="tpl.md"> | ||
## Markdown | ||
**This will go through $compile and will be effective** | ||
<button ng-click="doClick()"></button> | ||
</script> | ||
<div ng-controller="ClickHandler"> | ||
<div marked src="'tpl.md'" compile="true"></div> | ||
</div> | ||
``` | ||
```javascript | ||
.controller('ClickHandler', function() { | ||
this.doClick = function() { | ||
... | ||
}; | ||
}) | ||
``` | ||
### As a service | ||
@@ -129,0 +154,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31518
647
196
13