question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autoloader plugin feature: Support callback

See original GitHub issue

Information:

  • Prism version: 1.16.0
  • Plugins: autoloader
  • Environment: All environments

Description Right now, the autoloader plugin has no way to signal it is done working. It downloads the language as expected and highlights the piece of the code, but it doesn’t have a way to support a callback function for when it is done. As you can see in the source code: https://github.com/PrismJS/prism/blob/be909b18faa0afa899bb71ac1ab1f06c499277ce/plugins/autoloader/prism-autoloader.js#L286

Example

import { highlightElement, plugins } from 'prismjs/components/prism-core';
import 'prismjs/plugins/autoloader/prism-autoloader';
plugins.autoloader.languages_path = `https://unpkg.com/prismjs@latest/components/`;

const code = this.root.querySelector('code');
highlightElement(code, false, () => {
  alert('done highlighting');
});

In this example, the alert will show before actual highlighting is done, since the auto-loader plugin is still downloading the sources.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mAAdhaTTahcommented, Apr 3, 2020

A hook for that seems like a viable path forward. Will take a look at that.

1reaction
RunDevelopmentcommented, Mar 28, 2020

Autoloader loads language definitions and then highlights the element again, so I think that the current behavior of Prism, while not ideal, is correct.

It wouldn’t be too hard to implement as Autoloader-specific solution but we have other plugins that are also implemented by re-highlighting elements, so I’d personally prefer a unified solution. Thoughts? @mAAdhaTTah @Golmote

@nicojs Also, fetching some languages might fail. How should Prism behave in that case?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Autoloading And A Plugin Container In ...
We will walk through the steps of creating a plugin and investigate the use of autoloading and a plugin container.
Read more >
Using Namespaces and Autoloading in WordPress Plugins ...
So in this tutorial, we're going to put all of the pieces together. Specifically, we're going to revisit the source code of our...
Read more >
Plugins - Avisynth wiki
1 LoadPlugin · 2 LoadCPlugin · 3 LoadVirtualDubPlugin · 4 LoadVFAPIPlugin · 5 Plugin Autoload and Name Precedence · 6 Plugin Autoload and...
Read more >
Automatic class loading - MoodleDocs
This document describes how to use the functionality of the ... only should be used for existing code or APIs not supporting autoloading....
Read more >
Loading class files via autoload method
Perhaps show the code you are using in your autoloader - doing this from a namespace in a plugin is both possible and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found