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

Doubly check the manual flag #1957

Merged
merged 4 commits into from
Sep 3, 2019
Merged
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
28 changes: 19 additions & 9 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,29 @@ var script = document.currentScript || [].slice.call(document.getElementsByTagNa

if (script) {
_.filename = script.src;

if (script.hasAttribute('data-manual')) {
_.manual = true;
}
}

if (!_.manual && !script.hasAttribute('data-manual')) {
if(document.readyState !== 'loading') {
if (window.requestAnimationFrame) {
window.requestAnimationFrame(_.highlightAll);
} else {
window.setTimeout(_.highlightAll, 16);
}
if (!_.manual) {
function highlightAutomaticallyCallback() {
if (!_.manual) {
_.highlightAll();
}
else {
document.addEventListener('DOMContentLoaded', _.highlightAll);
}

if(document.readyState !== 'loading') {
if (window.requestAnimationFrame) {
window.requestAnimationFrame(highlightAutomaticallyCallback);
} else {
window.setTimeout(highlightAutomaticallyCallback, 16);
}
}
else {
document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
}
TimWolla marked this conversation as resolved.
Show resolved Hide resolved
}

return _;
Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

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

9 changes: 8 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,16 @@ <h1>Basic usage</h1>
<pre><code>&lt;pre>&lt;code class="language-css">p { color: red }&lt;/code>&lt;/pre></code></pre>
<p>If you use that pattern, the <code>&lt;pre></code> will automatically get the <code>language-xxxx</code> class (if it doesn’t already have it) and will be styled as a code block.</p>

<p>If you want to prevent any elements from being automatically highlighted, you can use the attribute <code>data-manual</code> on the <code>&lt;script></code> element you used for prism and use the <a href="extending.html#api">API</a>.
<p>If you want to prevent any elements from being automatically highlighted and instead use the <a href="extending.html#api">API</a>, you can set <code class="language-javascript">Prism.manual</code> to <code class="language-javascript">true</code> before the <code>DOMContentLoaded</code> event is fired. By setting the <code>data-manual</code> attribute on the <code>&lt;script></code> element containing Prism core, this will be done automatically.
Example:</p>
<pre><code>&lt;script src="prism.js" data-manual>&lt;/script></code></pre>
<p>or</p>
<pre><code>&lt;script>
window.Prism = window.Prism || {};
window.Prism.manual = true;
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
&lt;/script>
&lt;script src="prism.js">&lt;/script></code></pre>

<h2>Usage with CDNs</h2>

<p>In combination with CDNs, we recommend using the <a href="plugins/autoloader">Autoloader plugin</a> which automatically loads languages when necessary.</p>
Expand Down
28 changes: 19 additions & 9 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,19 +536,29 @@ var script = document.currentScript || [].slice.call(document.getElementsByTagNa

if (script) {
_.filename = script.src;

if (script.hasAttribute('data-manual')) {
_.manual = true;
}
}

if (!_.manual && !script.hasAttribute('data-manual')) {
if(document.readyState !== 'loading') {
if (window.requestAnimationFrame) {
window.requestAnimationFrame(_.highlightAll);
} else {
window.setTimeout(_.highlightAll, 16);
}
if (!_.manual) {
function highlightAutomaticallyCallback() {
if (!_.manual) {
_.highlightAll();
}
else {
document.addEventListener('DOMContentLoaded', _.highlightAll);
}

if(document.readyState !== 'loading') {
if (window.requestAnimationFrame) {
window.requestAnimationFrame(highlightAutomaticallyCallback);
} else {
window.setTimeout(highlightAutomaticallyCallback, 16);
}
}
else {
document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
}
}

return _;
Expand Down