Skip to content
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

Problem using compile="true" and language attribute/directive #35

Closed
jugglingcats opened this issue Jan 4, 2015 · 5 comments · May be fixed by #48
Closed

Problem using compile="true" and language attribute/directive #35

jugglingcats opened this issue Jan 4, 2015 · 5 comments · May be fixed by #48

Comments

@jugglingcats
Copy link

It seems that adding language attribute affects the compilation feature. I'm finding that the compile behaviour is a bit unpredictable - sometimes it works, sometimes not. But here is a plunkr based on the JSON pretty print example modified to show this issue.

http://plnkr.co/edit/2toXC6bCDpYNR8JPSTgD?p=preview

Notice that the expression {{editObject}} inside the last div is not being compiled. If you remove the language attribute it is compiled correctly.

Any suggested fix/workaround? It's not obvious looking at the code why this is happening.

Thanks!

@jugglingcats
Copy link
Author

Think I've figured out why this is happening (maybe). If in the plunkr you change the lang to "http" and then inspect element it's a bit more obvious. What we get is:

<code class="hljs http">{{<span class="hljs-attribute">editObject}}</span></code>.

As you can see, the AngularJS inline expression is broken up by the highlighting markup and this seems to happen before the compile step, so it's not interpreted.

What is a bit odd is that if lang="json", the inline expression is intact but still isn't compiled.

Maybe this is wrong interpretation but could be possible cause...

@jugglingcats
Copy link
Author

Another update. I found this link http://stackoverflow.com/questions/25581560/dynamic-syntax-highlighting-with-angularjs-and-highlight-js, and a slightly modified version of their directive (in the accepted answer) did the trick for me -- my use case is very simple.

@pc035860
Copy link
Owner

Hi @jugglingcats , thanks for the reporting!
I'm aware that the compile feature does have some issues. And I'm considering to rename the compile to interpolate, and that's what I really mean when implementing the feature.

The stackoverflow link is very helpful, thanks again.

@JonnyBGod
Copy link

Hi,

I am having this problem. I need to recompile every time a model is changed and this is not working. (not even compiling at startup)

Any plans to fix this behavior?

JonnyBGod added a commit to JonnyBGod/angular-highlightjs that referenced this issue Aug 25, 2015
pc035860 added a commit that referenced this issue Sep 6, 2015
- `language` no longer causes `compile`'s malfunction
- Rewrite `compile` with `$interpolate` service
- Add `interpolate` option, which is the same as `compile`
@pc035860
Copy link
Owner

pc035860 commented Sep 6, 2015

Hey @JonnyBGod ,

I've reviewed your PR. The real issue of language used with compile is that I didn't recompile the code after setting the language.

So I re-implement compile as a directive and avoid calling .highlight() too often with a debounce function. And I also fixed the issue reported by @jugglingcats that highlighted markup breaks angular expressions.

The code is now on master.
Test it by including https://rawgit.com/pc035860/angular-highlightjs/master/build/angular-highlightjs.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants