Skip to content

Commit

Permalink
Merge pull request #33 from TimvdLippe/expose-callback
Browse files Browse the repository at this point in the history
Expose callback function to element
  • Loading branch information
FredKSchott authored Aug 10, 2016
2 parents 07cbc77 + 5d18bf2 commit ecd3dc1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
11 changes: 10 additions & 1 deletion marked-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
observer: 'render',
type: Boolean,
value: false
},
/**
* Callback function invoked by Marked after HTML has been rendered.
* It must take two arguments: err and text and must return the resulting text.
*/
callback: {
observer: 'render',
type: Function,
value: null
}
},

Expand Down Expand Up @@ -200,7 +209,7 @@
pedantic: this.pedantic,
smartypants: this.smartypants
};
Polymer.dom(this._outputElement).innerHTML = marked(this.markdown, opts);
Polymer.dom(this._outputElement).innerHTML = marked(this.markdown, opts, this.callback);
this.fire('marked-render-complete');
},

Expand Down
31 changes: 30 additions & 1 deletion test/marked-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@
</template>
</test-fixture>

<test-fixture id="CustomCallbackFunction">
<template>
<marked-element>
<div id="output" class="markdown-html"></div>
<script type="text/markdown">
Some content
</script>
</marked-element>
</template>
</test-fixture>

<script>
'use strict';

Expand Down Expand Up @@ -121,7 +132,25 @@
});
test('has smartypants', function() {
expect(markedElement.sanitize).to.equal(false);
console.log(outputElement.innerHTML)
});
});

suite('<marked-element> has some options of marked available', function( ){
var markedElement;
var proofElement;
var outputElement;
setup(function() {
markedElement = fixture('CustomCallbackFunction');
proofElement = document.createElement('div');
outputElement = document.getElementById('output');
});
test('calls callback after render', function() {
proofElement.innerHTML = '<div>Overridden!</div>'
markedElement.callback = function(err, text) {
assert.equal(text, '<p>Some content</p>\n');
return '<div>Overridden!</div>';
}
expect(outputElement.innerHTML).to.equal(proofElement.innerHTML);
});
});

Expand Down

0 comments on commit ecd3dc1

Please sign in to comment.