Skip to content

Add the possibility to perform asynchronous calls in plugins/highligh… #3427

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions examples/dynamic-highlight.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<title>reveal.js</title>

<link rel="stylesheet" href="../dist/reset.css">
<link rel="stylesheet" href="../dist/reveal.css">
<link rel="stylesheet" href="../dist/theme/black.css">

<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="../plugin/highlight/monokai.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<pre><code data-src="https://pastebin.com/raw/6rzRvwdp" data-line-numbers data-noescape data-trim></code></pre>
</section>
</div>
</div>

<script src="../dist/reveal.js"></script>
<script src="../plugin/notes/notes.js"></script>
<script src="../plugin/markdown/markdown.js"></script>
<script src="../plugin/zoom/zoom.js"></script>
<script src="../plugin/highlight/highlight.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
slideNumber: true,

highlight: {
beforeHighlight: async hljs => {
const injectionFunction = async (el) => {
if (el.attributes['data-src']) {
const r = await fetch(el.attributes['data-src'].value);
el.innerHTML = await r.text();
console.log("Injected code from "+el.attributes['data-src'].value);
}
}
const promisesArray = [];
document.querySelectorAll('pre code').forEach((el) => promisesArray.push(injectionFunction(el)));
await Promise.all(promisesArray);
},
highlightOnLoad: true
},

// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealMarkdown, RevealHighlight, RevealNotes, RevealZoom ]
});
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugin/highlight/highlight.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading