Skip to content

Add parse and lexer options #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion dist/angular-marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ function markedProvider() {
this.defaults = opts;
};

/**
* @ngdoc method
* @name markedProvider#setLexer
* @methodOf hc.marked.service:markedProvider
*
* @param {object} lexer The lexer applied to [marked](https://github.com/chjj/marked#access-to-lexer-and-parser).
*/

self.setLexer = function (lexer) {
this.lexer = lexer;
};

/**
* @ngdoc method
* @name markedProvider#setParse
* @methodOf hc.marked.service:markedProvider
*
* @param {function} parse Overwrite the parse method called by marked.
*/

self.setParse = function (parse) {
this.parse = parse;
};

self.$get = ['$log', '$window', function ($log, $window) {
var m;

Expand Down Expand Up @@ -232,6 +256,20 @@ function markedProvider() {

m.setOptions(self.defaults);

// add marked lexer to defaults
self.defaults.lexer = m.lexer;

if (self.lexer) {
m.lexer = self.lexer;
};

// add marked parse method to defaults
self.defaults.parse = m.parse;

if (self.parser) {
m.parse = self.parse;
};

return m;
}];
}
Expand Down Expand Up @@ -333,7 +371,7 @@ function markedDirective(marked, $templateRequest, $compile) {

function set(text) {
text = unindent(String(text || ''));
element.html(marked(text, scope.opts || null));
element.html(marked.parse(text, scope.opts || null));
if (scope.$eval(attrs.compile)) {
$compile(element.contents())(scope.$parent);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-marked.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion lib/angular-marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ function markedProvider() {
this.defaults = opts;
};

/**
* @ngdoc method
* @name markedProvider#setLexer
* @methodOf hc.marked.service:markedProvider
*
* @param {object} lexer The lexer applied to [marked](https://github.com/chjj/marked#access-to-lexer-and-parser).
*/

self.setLexer = function (lexer) {
this.lexer = lexer;
};

/**
* @ngdoc method
* @name markedProvider#setParse
* @methodOf hc.marked.service:markedProvider
*
* @param {function} parse Overwrite the parse method called by marked.
*/

self.setParse = function (parse) {
this.parse = parse;
};

self.$get = ['$log', '$window', function ($log, $window) {
var m;

Expand Down Expand Up @@ -231,6 +255,20 @@ function markedProvider() {

m.setOptions(self.defaults);

// add marked lexer to defaults
self.defaults.lexer = m.lexer;

if (self.lexer) {
m.lexer = self.lexer;
};

// add marked parse method to defaults
self.defaults.parse = m.parse;

if (self.parser) {
m.parse = self.parse;
};

return m;
}];
}
Expand Down Expand Up @@ -332,7 +370,7 @@ function markedDirective(marked, $templateRequest, $compile) {

function set(text) {
text = unindent(String(text || ''));
element.html(marked(text, scope.opts || null));
element.html(marked.parse(text, scope.opts || null));
if (scope.$eval(attrs.compile)) {
$compile(element.contents())(scope.$parent);
}
Expand Down