UNPKG

angular-ivonet-markdown

Version:

AngularJS markdown directive with code highlighting and fully configurable

16 lines 1.27 kB
/* * Copyright 2015 Ivo Woltring <Webmaster@ivonet.nl> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ !function(n){angular.module("ivoMarkdown",["ngSanitize","hljs"]).provider("ivoMarkdownConfig",["hljsServiceProvider",function(o){var i={},t={tabReplace:" "};return{config:function(n){i=n},hljsOptions:function(n){t=n},$get:function(){return o.setOptions(t),new n.Converter(i)}}}]).directive("ivoMarkdown",["$sanitize","ivoMarkdownConfig","hljsService",function(n,o,i){return{restrict:"AE",link:function(t,e,r){function c(){angular.forEach(e[0].querySelectorAll("pre code"),function(o){n(i.highlightBlock(o))})}r.ivoMarkdown?t.$watch(r.ivoMarkdown,function(i){e.html(i?n(o.makeHtml(i)):""),c()}):(e.html(n(o.makeHtml(e.text()))),c())}}}])}(showdown);