This repository has been archived on 2020-10-11. You can view files and clone it, but cannot push or open issues or pull requests.
angularjs-batarang/panel/components/code/code.js
2014-10-22 07:43:29 -07:00

29 lines
600 B
JavaScript

'use strict';
angular.module('batarang.code', []).
directive('batCode', function() {
return {
restrict: 'A',
terminal: true,
scope: {
batCode: '='
},
link: function (scope, element, attrs) {
scope.$watch('batCode', function (newVal) {
if (newVal) {
element.html(replaceCodeInString(newVal));
}
});
}
};
});
// super lite version of markdown
var CODE_RE = /\`(.+?)\`/g;
function replaceCodeInString(str) {
return str.replace(CODE_RE, function (match, contents) {
return ['<code>', contents, '</code>'].join('');
});
}