-
Notifications
You must be signed in to change notification settings - Fork 53
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
Allow use of <pre><code> tags instead of <div hljs> #75
Comments
Hi @DavidZemon Modify https://github.com/pc035860/angular-highlightjs/blob/master/src/angular-highlightjs.js#L276, replace hljsDir = /*@ngInject*/ function ($parse) {
return {
restrict: 'EA',
controller: 'HljsCtrl',
compile: function(tElm, tAttrs, transclude) {
// get static code
// strip the starting "new line" character
var staticHTML = tElm[0].innerHTML.replace(/^(\r\n|\r|\n)/m, ''),
staticText = tElm[0].textContent.replace(/^(\r\n|\r|\n)/m, '');
// put template
// tElm.html('<pre><code class="hljs"></code></pre>');
return function postLink(scope, iElm, iAttrs, ctrl) {
var escapeCheck;
var attrs = attrGetter(iAttrs);
if (angular.isDefined(attrs('escape'))) {
escapeCheck = $parse(attrs('escape'));
} else if (angular.isDefined(attrs('no-escape'))) {
escapeCheck = $parse('false');
}
// ctrl.init(iElm.find('code'));
ctrl.init(iElm.addClass('hljs'));
if (attrs('onhighlight')) {
ctrl.highlightCallback(function () {
scope.$eval(attrs('onhighlight'));
});
}
if ((staticHTML || staticText) && shouldHighlightStatics(iAttrs)) {
var code;
// Auto-escape check
// default to "true"
if (escapeCheck && !escapeCheck(scope)) {
code = staticText;
}
else {
code = staticHTML;
}
ctrl.highlight(code);
}
scope.$on('$destroy', function () {
ctrl.release();
});
};
}
};
}; Rebuild the module with <pre><code hljs class="cpp">/*
A multi-line comment!
*/</code></pre> I'm not sure if specifying highlight language in <pre><code hljs hljs-language="cpp">/*
A multi-line comment!
*/</code></pre> |
Thank you so much, both for the edit and the quick response! Personally, I think this should be default behavior so I would be happy to submit this as a merge request if you'd like. Otherwise, this ticket can be closed out. I'm happy :D |
Can you please allow using the hljs directive inside a
<pre>
or<code>
tag instead of requiring it inside<div>
? When I do drop it in one of those, I get double boxes around my code in the rendered page.If this is something you'd rather not do for everyone, I'd be fine making the code change to my local copy of
angular-highlightjs.js
, but I don't know where to start.The text was updated successfully, but these errors were encountered: