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

Async highlighting #448

Closed
rayshan opened this issue Mar 27, 2014 · 6 comments

Comments

Projects
None yet
5 participants
@rayshan
Copy link

commented Mar 27, 2014

Hi, is there a way to know when highlighting is finished? Would be awesome to have ability to take a callback, so it'll work nicely with something like marked markdown parser:
https://github.com/chjj/marked

@isagalaev

This comment has been minimized.

Copy link
Member

commented Mar 30, 2014

You can do it by calling initHighlighting() instead of initHighlightingOnLoad() (the latter simply assigns the former to a page load event). Since initHighligting() is synchronous, you can call your code right after calling it:

$(document).ready(function() {
  hljs.initHighlighting();
  // post highlighting code
});
@isagalaev

This comment has been minimized.

Copy link
Member

commented Mar 30, 2014

I looked at "marked" and realized that you were probably looking for a node.js specific answer though you didn't mention it :-). And there's actually a whole section on using highlight.js in marked readme: https://github.com/chjj/marked#highlight

@rayshan

This comment has been minimized.

Copy link
Author

commented Mar 31, 2014

Thanks Ivan. I actually am using marked with angularjs for the front-end. I did read that section on marked's readme, however the async implementation is with pygmentize-bundled, and I like highlight.js :)

I think what you said about initHighlighting() will work. I'll wrap that in angularjs's $q and report back.

@michellehwang

This comment has been minimized.

Copy link

commented Apr 1, 2014

Is there a way to call the function after all the other scripts have loaded? I import html into my page and I would, ideally, like to highlight the code after all of the html has been loaded in. I tried using the async call at the very bottom of my code, but it only seems to highlight for the code that was initially on the page.

EDIT: I hacked my way around this by leaving a empty in my html and writing some JS to insert the code from the highlight.js usage. It kinda works non-deterministically though..

@Sannis Sannis changed the title async highlighting Async highlighting Apr 1, 2014

@Sannis Sannis added the feature label Apr 5, 2014

@marceloboeira

This comment has been minimized.

Copy link

commented Aug 28, 2014

+1

@isagalaev

This comment has been minimized.

Copy link
Member

commented Aug 28, 2014

OK, I'm not really sure why the issue is still open. The original question seems to be resolved by my answer. Please direct other question into our discussion group.

@isagalaev isagalaev closed this Aug 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.