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

RFC? Prism Support? #56

Closed
wants to merge 4 commits into from
Closed

Conversation

NullVoxPopuli
Copy link

@NullVoxPopuli NullVoxPopuli commented Oct 17, 2018

so, I'm using Prism, as it has better syntax detection / parsing.
I had to disable highlight, and change a few other things.

It seems highlight.js isn't up to spec with semantics, compared with prism.

Related: #55

@ef4
Copy link
Owner

ef4 commented Oct 17, 2018

If prism is strictly better we can just switch.

Or we can split ember-code-snippet into two separate libraries. One would focus only on code highlighting, the other would focus on discovering and packaging up the snippets.

@patocallaghan
Copy link

Funnily enough, yesterday I was looking for this exact thing. We've found Prism is better for handlebars syntax highlighting as it adds more styleable classes than highlightjs does.

HighlightJS
image
image

Prism
image
image

@@ -39,10 +39,12 @@ export default Ember.Component.extend({
}),

didInsertElement: function(){
Highlight.highlightBlock(this.get('element'));
// Highlight.highlightBlock(this.get('element'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had hacked this in which worked for our use case. Once you have Prism on the page you can do something like the following:

const Prism = self.Prism;
let codeElement = this.get('element').querySelector('code');
let highlighted = Prism.highlight(codeElement.innerText.trim(), Prism.languages[this.get('language')], this.get('language'));
codeElement.innerHTML = highlighted;

This way if you have a tabbed UI like in ember-cli-addons-docs the syntax highlighting will still work as you switch between the tabs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is also

Prism.highlightAllUnder(this.element);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh TIL 🙌

@samselikoff
Copy link
Contributor

Would be great to decouple as we have our own custom highlighter code too.

@simonihmig
Copy link
Collaborator

Or we can split ember-code-snippet into two separate libraries. One would focus only on code highlighting, the other would focus on discovering and packaging up the snippets.

Here is a first stab at it: #62 (covering the latter concern)

@ef4
Copy link
Owner

ef4 commented Jun 24, 2019

This is now done, thanks @simonihmig.

ember-code-snippet 3.0.0 is a breaking change that switches us to "bring-your-own highlighter component". The README shows how to use it with prism.

@ef4 ef4 closed this Jun 24, 2019
@samselikoff
Copy link
Contributor

Nice work!! Will have to upgrade AddonDocs to use Prism now, think it will be much better 👍

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 this pull request may close these issues.

None yet

5 participants