You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
angularjs-batarang/panel/components/code/code.js

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('');
});
}