How to compile an extension's result?
See original GitHub issueI was able to make a custom extension, but I couldn’t find how to compile the contained directives.
The given tag is replaced, but the resulting HTML is not processed by Angular.
How to compile the result with Angular? I don’t know if it is even possible to define a compilation from .config(). Should the extension be included somewhere else?
Here is a test extension replacing &test by '<simple-element></simple-element>:
angular.module('myApp')
.config(['$showdownProvider', function($showdownProvider) {
myExt = function () {
return [{
type: 'output',
filter: function (text) {
var regex = /(<p>&test<\/p>)+/g;
text = text.replace(
regex,
'<simple-element>extension: ok, directive: NOT</simple-element>'
);
return text;
}
}];
};
$showdownProvider.loadExtension(myExt);
}]);
The simpleElement directive:
angular.module('myApp')
.directive('simpleElement', [function() {
return {
restrict: 'E',
replace: true,
template: '<div>Everything works!</div>'
}
}]);
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to compile a Google Chrome extension out of code I ...
1 Answer 1 · First organize your script, source file(s) and explicitly create the manifest. · You do not need to alter that...
Read more >Chrome Extensions getting started guides
These tutorials not only teach you how to build real-world extensions but also strive to share development tips and best practices.
Read more >How to Build a Chrome Extension - Neil Patel
Build a Chrome Extension Step 4: Load Your Extension into Chrome and Check for Errors · Go to chrome://extensions in your Google Chrome...
Read more >Google Chrome Extensions: How to build an ... - YouTube
Brian Kennish, a developer advocate for Google Chrome presents how to build an extension for Google Chrome.
Read more >Your First Extension - Visual Studio Code
Then, inside the editor, press F5. This will compile and run the extension in a new Extension Development Host window. Run the Hello...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Here’s what I ended up with @ntopulos, hopefully this helps.
I created my own
markdowndirective as an alternative to themardown-to-htmldirective:Please note that this is an exact copy of the
markdown-to-htmldirective with the exception of this:template: '<div bind-html-compile="trustedHtml"></div>'.With that being done, I created another directive
bind-html-compilewhich compiled the html given to it which looks like so:Usage:
Voilà!
Additionally, to keep my organization a little cleaner, I created the
showdown extensionsas angular constants like so:And then injected and registered them in the config:
Hope this helps!
Thank you both for your replies! Unfortunately I wasn’t able to make it work, what do I miss?
I’ve created these jsfiddles, and as you can see the directive is never executed when generated by a ShowDown extension:
In each example I use the extension to replace
&testinside the markdown string by<simple-element>extension: executed, directive: NOT executed</simple-element>. Then theSimpleElementdirective should replace this by<div>directive executed</div>, but it doesn’t.Edit (works):
Actually @jspizziri’s method worked! https://jsfiddle.net/ov0q23Le/1/
I thought it didn’t because of a local issue with this line that I forgot to uncomment when creating the jsfiddle:
scope.trustedHtml = ($showdown.getOption('sanitize')) ? $sanitize(showdownHTML) : $sce.trustAsHtml(showdownHTML);