pc035860 / angular-highlightjs

AngularJS directive for syntax highlighting with highlight.js
http://pc035860.github.io/angular-highlightjs/example/
MIT License
294 stars 53 forks source link

Stop adding ="" to valueless html attributes #60

Open chrisfay opened 8 years ago

chrisfay commented 8 years ago

[See this discussion https://github.com/isagalaev/highlight.js/issues/1058]

How do I configure so that this:

<foo bar></foo>

...doesn't become this after it's ran through highlightjs:

<foo bar=""></foo>

screen shot 2016-02-02 at 12 57 39 pm screen shot 2016-02-02 at 12 57 31 pm

pc035860 commented 8 years ago

Hi, I guess you already got the answer from isagalaev/highlight.js/issues/1058.

What you actually need is preventing your <foo bar></foo> to be parsed by browser before AngularJS gets it hands on it.

hljs source or hljs include can do the trick.

See #30 for the previous discussion.

An example of solving it with hljs-include

<div hljs hljs-include="'the-foo-bar-source'"></div>

<script id="the-foo-bar-source" type="text/ng-template">
<foo bar></foo>
</script>
chrisfay commented 8 years ago

Ahhh, gotcha. I think I was misunderstanding at what stage the attributes were getting modified before rendering. This makes sense, thanks!

Chris

On Wed, Feb 3, 2016 at 11:26 AM Chih-Hsuan Fan notifications@github.com wrote:

Hi, I guess you already got the answer from isagalaev/highlight.js#1058 https://github.com/isagalaev/highlight.js/issues/1058.

What you actually need is preventing your to be parsed by browser before AngularJS gets it hands on it.

hljs source http://pc035860.github.io/angular-highlightjs/example/#/hljs-source or hljs include http://pc035860.github.io/angular-highlightjs/example/#/hljs-include can do the trick.

See #30 https://github.com/pc035860/angular-highlightjs/issues/30 for the previous discussion.

An example of solving it with hljs-include

— Reply to this email directly or view it on GitHub https://github.com/pc035860/angular-highlightjs/issues/60#issuecomment-179390293 .

Chris Fay http://www.chrisfay.net chrislfay@gmail.com

pc035860 commented 8 years ago

BTW, you can also prevent from browser parsing by manually escaping those code you put inside hljs directive, and use it with hljs-no-escape option.

For example

<div hljs hljs-no-escape>
&lt;foo bar&gt;&lt;/foo&gt;
</div>