2015-12-27 16:59:38 +01:00
( 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 ) {
/ *
* This is a modified version of angular - marked . js for Pony . fm to provide compatibility with Angular 1.2 . 0.
*
* angular - marked
* ( c ) 2014 J . Harshbarger
* Licensed MIT
* /
/* jshint undef: true, unused: true */
/* global angular, marked */
'use strict' ;
/ * *
* @ ngdoc overview
* @ name index
*
* @ description
* AngularJS Markdown using [ marked ] ( https : //github.com/chjj/marked).
*
* # # Why ?
*
* I wanted to use [ marked ] ( https : //github.com/chjj/marked) instead of [showdown](https://github.com/coreyti/showdown) as used in [angular-markdown-directive](https://github.com/btford/angular-markdown-directive) as well as expose the option to globally set defaults.
*
* # # How ?
*
* - { @ link hc . marked . directive : marked As a directive }
* - { @ link hc . marked . service : marked As a service }
* - { @ link hc . marked . service : markedProvider Set default options }
*
* @ example
Convert markdown to html at run time . For example :
< example module = "app" >
< file name = "example.html" >
< form ng - controller = "MainController" >
Markdown : < br / >
2016-05-20 01:08:57 +02:00
< textarea ng - model = "my_markdown" cols = "60" rows = "5" class = "col-md-8" > < /textarea><br / >
2015-12-27 16:59:38 +01:00
Output : < br / >
< div marked = "my_markdown" / >
< / f o r m >
< / f i l e >
< file name = "example.js" >
function MainController ( $scope ) {
$scope . my _markdown = "*This* **is** [markdown](https://daringfireball.net/projects/markdown/)" ;
}
angular . module ( 'app' , [ 'hc.marked' ] ) . controller ( 'MainController' , MainController ) ;
< / f i l e >
< / e x a m p l e >
*
* /
/ * *
* @ ngdoc overview
* @ name hc . marked
* @ description # angular - marked ( core module )
# Installation
First include angular - marked . js in your HTML :
` ` ` js
< script src = "angular-marked.js" >
` ` `
Then load the module in your application by adding it as a dependency :
` ` ` js
angular . module ( 'yourApp' , [ 'hc.marked' ] ) ;
` ` `
With that you ' re ready to get started !
* /
module . exports = 'hc.marked' ;
angular . module ( 'hc.marked' , [ ] )
/ * *
* @ ngdoc service
* @ name hc . marked . service : marked
* @ requires $window
* @ description
* A reference to the [ marked ] ( https : //github.com/chjj/marked) parser.
*
* @ example
< example module = "app" >
< file name = "example.html" >
< div ng - controller = "MainController" >
html : { { html } }
< / d i v >
< / f i l e >
< file name = "example.js" >
function MainController ( $scope , marked ) {
$scope . html = marked ( '#TEST' ) ;
}
angular . module ( 'app' , [ 'hc.marked' ] ) . controller ( 'MainController' , MainController ) ;
< / f i l e >
< / e x a m p l e >
* * /
/ * *
* @ ngdoc service
* @ name hc . marked . service : markedProvider
* @ description
* Use ` markedProvider ` to change the default behavior of the { @ link hc . marked . service : marked marked } service .
*
* @ example
# # Example using [ google - code - prettify syntax highlighter ] ( https : //code.google.com/p/google-code-prettify/) (must include google-code-prettify.js script). Also works with [highlight.js Javascript syntax highlighter](http://highlightjs.org/).
< example module = "myAppA" >
< file name = "exampleA.js" >
angular . module ( 'myAppA' , [ 'hc.marked' ] )
. config ( [ 'markedProvider' , function ( markedProvider ) {
markedProvider . setOptions ( {
gfm : true ,
tables : true ,
highlight : function ( code ) {
return prettyPrintOne ( code ) ;
}
} ) ;
} ] ) ;
< / f i l e >
< file name = "exampleA.html" >
< marked >
` ` ` js
angular . module ( 'myAppA' , [ 'hc.marked' ] )
. config ( [ 'markedProvider' , function ( markedProvider ) {
markedProvider . setOptions ( {
gfm : true ,
tables : true ,
highlight : function ( code ) {
return prettyPrintOne ( code ) ;
}
} ) ;
} ] ) ;
` ` `
< / m a r k e d >
< / f i l e >
< / e x a m p l e >
# # Example overriding the way custom markdown links are displayed
< example module = "myAppB" >
< file name = "exampleB.js" >
angular . module ( 'myAppB' , [ 'hc.marked' ] )
. config ( [ 'markedProvider' , function ( markedProvider ) {
markedProvider . setRenderer ( {
link : function ( href , title , text ) {
return "<a href='" + href + "'" + ( title ? " title='" + title + "'" : '' ) + " target='_blank'>" + text + "</a>" ;
}
} ) ;
} ] ) ;
< / f i l e >
< file name = "exampleB.html" >
< marked >
This is [ an example ] ( http : //example.com/ "Title") inline link.
[ This link ] ( http : //example.net/) has no title attribute.
< / m a r k e d >
< / f i l e >
< / e x a m p l e >
* * /
. provider ( 'marked' , function ( ) {
var self = this ;
/ * *
* @ ngdoc method
* @ name markedProvider # setRenderer
* @ methodOf hc . marked . service : markedProvider
*
* @ param { object } opts Default renderer options for [ marked ] ( https : //github.com/chjj/marked#overriding-renderer-methods).
* /
self . setRenderer = function ( opts ) {
this . renderer = opts ;
} ;
/ * *
* @ ngdoc method
* @ name markedProvider # setOptions
* @ methodOf hc . marked . service : markedProvider
*
* @ param { object } opts Default options for [ marked ] ( https : //github.com/chjj/marked#options-1).
* /
self . setOptions = function ( opts ) { // Store options for later
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 ;
}
// override rendered markdown html
// with custom definitions if defined
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 ] ] ;
}
// add the new renderer to the options if need be
self . defaults = self . defaults || { } ;
self . defaults . renderer = r ;
}
m . setOptions ( self . defaults ) ;
return m ;
} ] ;
} )
// TODO: filter and tests */
// app.filter('marked', ['marked', function(marked) {
// return marked;
// }]);
/ * *
* @ ngdoc directive
* @ name hc . marked . directive : marked
* @ restrict AE
* @ element any
*
* @ description
* Compiles source test into HTML .
*
* @ param { expression = } marked The source text to be compiled . If blank uses content as the source .
* @ param { expression = } opts Hash of options that override defaults .
* @ 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'" ` .
*
* @ example
# # A simple block of text
< example module = "hc.marked" >
< file name = "exampleA.html" >
* < marked >
* # # # Markdown directive
*
* * It works ! *
*
* * This * * * is * * [ markdown ] ( https : //daringfireball.net/projects/markdown/) in the view.
* < / m a r k e d >
< / f i l e >
< / e x a m p l e >
# # Bind to a scope variable
< example module = "app" >
< file name = "exampleB.html" >
< form ng - controller = "MainController" >
Markdown : < br / >
2016-05-20 01:08:57 +02:00
< textarea ng - model = "my_markdown" class = "col-md-8" cols = "60" rows = "5" > < /textarea><br / >
2015-12-27 16:59:38 +01:00
Output : < br / >
< blockquote marked = "my_markdown" > < / b l o c k q u o t e >
< / f o r m >
< / f i l e >
< file name = "exampleB.js" >
* function MainController ( $scope ) {
* $scope . my _markdown = '*This* **is** [markdown](https://daringfireball.net/projects/markdown/)' ;
* $scope . my _markdown += ' in a scope variable' ;
* }
* angular . module ( 'app' , [ 'hc.marked' ] ) . controller ( 'MainController' , MainController ) ;
< / f i l e >
< / e x a m p l e >
# # Include a markdown file :
< example module = "hc.marked" >
< file name = "exampleC.html" >
< div marked src = "'include.html'" / >
< / f i l e >
* < file name = "include.html" >
* * This * * * is * * [ markdown ] ( https : //daringfireball.net/projects/markdown/) in a include file.
* < / f i l e >
< / e x a m p l e >
* /
. directive ( 'marked' , [ 'marked' , function ( marked ) {
return {
restrict : 'AE' ,
replace : true ,
scope : {
opts : '=' ,
marked : '='
} ,
link : function ( scope , element , attrs ) {
set ( scope . marked || element . text ( ) || '' ) ;
if ( attrs . marked ) {
scope . $watch ( 'marked' , set ) ;
}
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 )
} ) ;