Skip to content

Commit

Permalink
Core: Added better error message for missing grammars (#3311)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Feb 2, 2022
1 parent 3f8cc5a commit 2cc4660
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ var Prism = (function (_self) {
language: language
};
_.hooks.run('before-tokenize', env);
if (!env.grammar) {
throw new Error('The language "' + env.language + '" has no grammar.');
}
env.tokens = _.tokenize(env.code, env.grammar);
_.hooks.run('after-tokenize', env);
return Token.stringify(_.util.encode(env.tokens), env.language);
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.

6 changes: 3 additions & 3 deletions docs/Prism.hooks.html
Original file line number Diff line number Diff line change
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#line714">line 714</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line717">line 717</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#line729">line 729</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line732">line 732</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#line746">line 746</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line749">line 749</a>
</li></ul></dd>


Expand Down
2 changes: 1 addition & 1 deletion docs/Prism.html
Original file line number Diff line number Diff line change
Expand Up @@ -1244,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#line691">line 691</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line694">line 694</a>
</li></ul></dd>


Expand Down
8 changes: 4 additions & 4 deletions docs/Token.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h4 class="name" id="Token"><span class="type-signature"></span>new Token<span c

<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#line780">line 780</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line783">line 783</a>
</li></ul></dd>


Expand Down Expand Up @@ -364,7 +364,7 @@ <h4 class="name" id="alias"><span class="type-signature"></span>alias<span class

<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#line807">line 807</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line810">line 810</a>
</li></ul></dd>


Expand Down Expand Up @@ -447,7 +447,7 @@ <h4 class="name" id="content"><span class="type-signature"></span>content<span c

<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#line799">line 799</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line802">line 802</a>
</li></ul></dd>


Expand Down Expand Up @@ -524,7 +524,7 @@ <h4 class="name" id="type"><span class="type-signature"></span>type<span class="

<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#line790">line 790</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line793">line 793</a>
</li></ul></dd>


Expand Down
Loading

0 comments on commit 2cc4660

Please sign in to comment.