Skip to content

Commit

Permalink
Core: Document disableWorkerMessageHandler (#3088)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Schmidt <msrd0000@gmail.com>
  • Loading branch information
jakearchibald and RunDevelopment committed Sep 23, 2021
1 parent 9f4c0e7 commit 213cf7b
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 27 deletions.
21 changes: 21 additions & 0 deletions components/prism-core.js
Expand Up @@ -49,6 +49,27 @@ var Prism = (function (_self) {
* @public
*/
manual: _self.Prism && _self.Prism.manual,
/**
* By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
* `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
* own worker, you don't want it to do this.
*
* By setting this value to `true`, Prism will not add its own listeners to the worker.
*
* You obviously have to change this value before Prism executes. To do this, you can add an
* empty Prism object into the global scope before loading the Prism script like this:
*
* ```js
* window.Prism = window.Prism || {};
* Prism.disableWorkerMessageHandler = true;
* // Load Prism's script
* ```
*
* @default false
* @type {boolean}
* @memberof Prism
* @public
*/
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,

/**
Expand Down
8 changes: 4 additions & 4 deletions docs/Prism.hooks.html
Expand Up @@ -36,7 +36,7 @@

<input type="text" id="nav-search" placeholder="Search" />

<h2><a href="index.html">Home</a></h2><h2><a href="https://prismjs.com" class="menu-item" id="website_link" >PrismJS</a></h2><h2><a href="https://github.com/PrismJS/prism" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Classes</h3><ul><li><a href="Token.html">Token</a></li></ul><h3>Namespaces</h3><ul><li><a href="Prism.html">Prism</a><ul class='members'><li data-type='member'><a href="Prism.html#.manual">manual</a></li></ul><ul class='methods'><li data-type='method'><a href="Prism.html#.highlight">highlight</a></li><li data-type='method'><a href="Prism.html#.highlightAll">highlightAll</a></li><li data-type='method'><a href="Prism.html#.highlightAllUnder">highlightAllUnder</a></li><li data-type='method'><a href="Prism.html#.highlightElement">highlightElement</a></li><li data-type='method'><a href="Prism.html#.tokenize">tokenize</a></li></ul></li><li><a href="Prism.hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="Prism.hooks.html#.add">add</a></li><li data-type='method'><a href="Prism.hooks.html#.run">run</a></li></ul></li><li><a href="Prism.languages.html">languages</a><ul class='methods'><li data-type='method'><a href="Prism.languages.html#.extend">extend</a></li><li data-type='method'><a href="Prism.languages.html#.insertBefore">insertBefore</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#Grammar">Grammar</a></li><li><a href="global.html#GrammarToken">GrammarToken</a></li><li><a href="global.html#HighlightCallback">HighlightCallback</a></li><li><a href="global.html#HookCallback">HookCallback</a></li><li><a href="global.html#TokenStream">TokenStream</a></li></ul>
<h2><a href="index.html">Home</a></h2><h2><a href="https://prismjs.com" class="menu-item" id="website_link" >PrismJS</a></h2><h2><a href="https://github.com/PrismJS/prism" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Classes</h3><ul><li><a href="Token.html">Token</a></li></ul><h3>Namespaces</h3><ul><li><a href="Prism.html">Prism</a><ul class='members'><li data-type='member'><a href="Prism.html#.disableWorkerMessageHandler">disableWorkerMessageHandler</a></li><li data-type='member'><a href="Prism.html#.manual">manual</a></li></ul><ul class='methods'><li data-type='method'><a href="Prism.html#.highlight">highlight</a></li><li data-type='method'><a href="Prism.html#.highlightAll">highlightAll</a></li><li data-type='method'><a href="Prism.html#.highlightAllUnder">highlightAllUnder</a></li><li data-type='method'><a href="Prism.html#.highlightElement">highlightElement</a></li><li data-type='method'><a href="Prism.html#.tokenize">tokenize</a></li></ul></li><li><a href="Prism.hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="Prism.hooks.html#.add">add</a></li><li data-type='method'><a href="Prism.hooks.html#.run">run</a></li></ul></li><li><a href="Prism.languages.html">languages</a><ul class='methods'><li data-type='method'><a href="Prism.languages.html#.extend">extend</a></li><li data-type='method'><a href="Prism.languages.html#.insertBefore">insertBefore</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#Grammar">Grammar</a></li><li><a href="global.html#GrammarToken">GrammarToken</a></li><li><a href="global.html#HighlightCallback">HighlightCallback</a></li><li><a href="global.html#HookCallback">HookCallback</a></li><li><a href="global.html#TokenStream">TokenStream</a></li></ul>
</nav>

<div id="main">
Expand Down Expand Up @@ -73,7 +73,7 @@ <h2>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line675">line 675</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line696">line 696</a>
</li></ul></dd>


Expand Down Expand Up @@ -152,7 +152,7 @@ <h4 class="name" id=".add"><span class="type-signature">(static) </span>add<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line690">line 690</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line711">line 711</a>
</li></ul></dd>


Expand Down Expand Up @@ -314,7 +314,7 @@ <h4 class="name" id=".run"><span class="type-signature">(static) </span>run<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line707">line 707</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line728">line 728</a>
</li></ul></dd>


Expand Down
99 changes: 93 additions & 6 deletions docs/Prism.html
Expand Up @@ -36,7 +36,7 @@

<input type="text" id="nav-search" placeholder="Search" />

<h2><a href="index.html">Home</a></h2><h2><a href="https://prismjs.com" class="menu-item" id="website_link" >PrismJS</a></h2><h2><a href="https://github.com/PrismJS/prism" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Classes</h3><ul><li><a href="Token.html">Token</a></li></ul><h3>Namespaces</h3><ul><li><a href="Prism.html">Prism</a><ul class='members'><li data-type='member'><a href="Prism.html#.manual">manual</a></li></ul><ul class='methods'><li data-type='method'><a href="Prism.html#.highlight">highlight</a></li><li data-type='method'><a href="Prism.html#.highlightAll">highlightAll</a></li><li data-type='method'><a href="Prism.html#.highlightAllUnder">highlightAllUnder</a></li><li data-type='method'><a href="Prism.html#.highlightElement">highlightElement</a></li><li data-type='method'><a href="Prism.html#.tokenize">tokenize</a></li></ul></li><li><a href="Prism.hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="Prism.hooks.html#.add">add</a></li><li data-type='method'><a href="Prism.hooks.html#.run">run</a></li></ul></li><li><a href="Prism.languages.html">languages</a><ul class='methods'><li data-type='method'><a href="Prism.languages.html#.extend">extend</a></li><li data-type='method'><a href="Prism.languages.html#.insertBefore">insertBefore</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#Grammar">Grammar</a></li><li><a href="global.html#GrammarToken">GrammarToken</a></li><li><a href="global.html#HighlightCallback">HighlightCallback</a></li><li><a href="global.html#HookCallback">HookCallback</a></li><li><a href="global.html#TokenStream">TokenStream</a></li></ul>
<h2><a href="index.html">Home</a></h2><h2><a href="https://prismjs.com" class="menu-item" id="website_link" >PrismJS</a></h2><h2><a href="https://github.com/PrismJS/prism" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Classes</h3><ul><li><a href="Token.html">Token</a></li></ul><h3>Namespaces</h3><ul><li><a href="Prism.html">Prism</a><ul class='members'><li data-type='member'><a href="Prism.html#.disableWorkerMessageHandler">disableWorkerMessageHandler</a></li><li data-type='member'><a href="Prism.html#.manual">manual</a></li></ul><ul class='methods'><li data-type='method'><a href="Prism.html#.highlight">highlight</a></li><li data-type='method'><a href="Prism.html#.highlightAll">highlightAll</a></li><li data-type='method'><a href="Prism.html#.highlightAllUnder">highlightAllUnder</a></li><li data-type='method'><a href="Prism.html#.highlightElement">highlightElement</a></li><li data-type='method'><a href="Prism.html#.tokenize">tokenize</a></li></ul></li><li><a href="Prism.hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="Prism.hooks.html#.add">add</a></li><li data-type='method'><a href="Prism.hooks.html#.run">run</a></li></ul></li><li><a href="Prism.languages.html">languages</a><ul class='methods'><li data-type='method'><a href="Prism.languages.html#.extend">extend</a></li><li data-type='method'><a href="Prism.languages.html#.insertBefore">insertBefore</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#Grammar">Grammar</a></li><li><a href="global.html#GrammarToken">GrammarToken</a></li><li><a href="global.html#HighlightCallback">HighlightCallback</a></li><li><a href="global.html#HookCallback">HookCallback</a></li><li><a href="global.html#TokenStream">TokenStream</a></li></ul>
</nav>

<div id="main">
Expand Down Expand Up @@ -155,6 +155,93 @@ <h3 class="subsection-title">Members</h3>



<h4 class="name" id=".disableWorkerMessageHandler"><span class="type-signature">(static) </span>disableWorkerMessageHandler<span class="type-signature"> :boolean</span></h4>





<dl class="details">


<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line73">line 73</a>
</li></ul></dd>

























<dt class="tag-default">Default Value:</dt>
<dd class="tag-default"><ul class="dummy">
<li>false</li>
</ul></dd>







</dl>





<div class="description usertext">
<p>By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
<code>addEventListener</code> to communicate with its parent instance. However, if you're using Prism manually in your
own worker, you don't want it to do this.</p>
<p>By setting this value to <code>true</code>, Prism will not add its own listeners to the worker.</p>
<p>You obviously have to change this value before Prism executes. To do this, you can add an
empty Prism object into the global scope before loading the Prism script like this:</p>
<pre class="prettyprint source lang-js"><code>window.Prism = window.Prism || {};
Prism.disableWorkerMessageHandler = true;
// Load Prism's script
</code></pre>
</div>



<h5>Type:</h5>
<ul>
<li>

<span class="param-type">boolean</span>


</li>
</ul>








<h4 class="name" id=".manual"><span class="type-signature">(static) </span>manual<span class="type-signature"> :boolean</span></h4>


Expand Down Expand Up @@ -263,7 +350,7 @@ <h4 class="name" id=".highlight"><span class="type-signature">(static) </span>hi

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line616">line 616</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line637">line 637</a>
</li></ul></dd>


Expand Down Expand Up @@ -480,7 +567,7 @@ <h4 class="name" id=".highlightAll"><span class="type-signature">(static) </span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line458">line 458</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line479">line 479</a>
</li></ul></dd>


Expand Down Expand Up @@ -676,7 +763,7 @@ <h4 class="name" id=".highlightAllUnder"><span class="type-signature">(static) <

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line477">line 477</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line498">line 498</a>
</li></ul></dd>


Expand Down Expand Up @@ -911,7 +998,7 @@ <h4 class="name" id=".highlightElement"><span class="type-signature">(static) </

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line523">line 523</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line544">line 544</a>
</li></ul></dd>


Expand Down Expand Up @@ -1157,7 +1244,7 @@ <h4 class="name" id=".tokenize"><span class="type-signature">(static) </span>tok

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line652">line 652</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line673">line 673</a>
</li></ul></dd>


Expand Down
8 changes: 4 additions & 4 deletions docs/Prism.languages.html
Expand Up @@ -36,7 +36,7 @@

<input type="text" id="nav-search" placeholder="Search" />

<h2><a href="index.html">Home</a></h2><h2><a href="https://prismjs.com" class="menu-item" id="website_link" >PrismJS</a></h2><h2><a href="https://github.com/PrismJS/prism" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Classes</h3><ul><li><a href="Token.html">Token</a></li></ul><h3>Namespaces</h3><ul><li><a href="Prism.html">Prism</a><ul class='members'><li data-type='member'><a href="Prism.html#.manual">manual</a></li></ul><ul class='methods'><li data-type='method'><a href="Prism.html#.highlight">highlight</a></li><li data-type='method'><a href="Prism.html#.highlightAll">highlightAll</a></li><li data-type='method'><a href="Prism.html#.highlightAllUnder">highlightAllUnder</a></li><li data-type='method'><a href="Prism.html#.highlightElement">highlightElement</a></li><li data-type='method'><a href="Prism.html#.tokenize">tokenize</a></li></ul></li><li><a href="Prism.hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="Prism.hooks.html#.add">add</a></li><li data-type='method'><a href="Prism.hooks.html#.run">run</a></li></ul></li><li><a href="Prism.languages.html">languages</a><ul class='methods'><li data-type='method'><a href="Prism.languages.html#.extend">extend</a></li><li data-type='method'><a href="Prism.languages.html#.insertBefore">insertBefore</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#Grammar">Grammar</a></li><li><a href="global.html#GrammarToken">GrammarToken</a></li><li><a href="global.html#HighlightCallback">HighlightCallback</a></li><li><a href="global.html#HookCallback">HookCallback</a></li><li><a href="global.html#TokenStream">TokenStream</a></li></ul>
<h2><a href="index.html">Home</a></h2><h2><a href="https://prismjs.com" class="menu-item" id="website_link" >PrismJS</a></h2><h2><a href="https://github.com/PrismJS/prism" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Classes</h3><ul><li><a href="Token.html">Token</a></li></ul><h3>Namespaces</h3><ul><li><a href="Prism.html">Prism</a><ul class='members'><li data-type='member'><a href="Prism.html#.disableWorkerMessageHandler">disableWorkerMessageHandler</a></li><li data-type='member'><a href="Prism.html#.manual">manual</a></li></ul><ul class='methods'><li data-type='method'><a href="Prism.html#.highlight">highlight</a></li><li data-type='method'><a href="Prism.html#.highlightAll">highlightAll</a></li><li data-type='method'><a href="Prism.html#.highlightAllUnder">highlightAllUnder</a></li><li data-type='method'><a href="Prism.html#.highlightElement">highlightElement</a></li><li data-type='method'><a href="Prism.html#.tokenize">tokenize</a></li></ul></li><li><a href="Prism.hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="Prism.hooks.html#.add">add</a></li><li data-type='method'><a href="Prism.hooks.html#.run">run</a></li></ul></li><li><a href="Prism.languages.html">languages</a><ul class='methods'><li data-type='method'><a href="Prism.languages.html#.extend">extend</a></li><li data-type='method'><a href="Prism.languages.html#.insertBefore">insertBefore</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#Grammar">Grammar</a></li><li><a href="global.html#GrammarToken">GrammarToken</a></li><li><a href="global.html#HighlightCallback">HighlightCallback</a></li><li><a href="global.html#HookCallback">HookCallback</a></li><li><a href="global.html#TokenStream">TokenStream</a></li></ul>
</nav>

<div id="main">
Expand Down Expand Up @@ -73,7 +73,7 @@ <h2>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line260">line 260</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line281">line 281</a>
</li></ul></dd>


Expand Down Expand Up @@ -154,7 +154,7 @@ <h4 class="name" id=".extend"><span class="type-signature">(static) </span>exten

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line297">line 297</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line318">line 318</a>
</li></ul></dd>


Expand Down Expand Up @@ -354,7 +354,7 @@ <h4 class="name" id=".insertBefore"><span class="type-signature">(static) </span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line382">line 382</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line403">line 403</a>
</li></ul></dd>


Expand Down

0 comments on commit 213cf7b

Please sign in to comment.