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

Core: Token.stringify will now call util.encode #1844

Closed
Closed
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
14 changes: 4 additions & 10 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,8 @@ var _ = {
* @memberof Prism
*/
util: {
encode: function encode(tokens) {
if (tokens instanceof Token) {
return new Token(tokens.type, encode(tokens.content), tokens.alias);
} else if (Array.isArray(tokens)) {
return tokens.map(encode);
} else {
return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
}
encode: function (str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
},

/**
Expand Down Expand Up @@ -607,7 +601,7 @@ var _ = {
_.hooks.run('before-tokenize', env);
env.tokens = _.tokenize(env.code, env.grammar);
_.hooks.run('after-tokenize', env);
return Token.stringify(_.util.encode(env.tokens), env.language);
return Token.stringify(env.tokens, env.language);
},

/**
Expand Down Expand Up @@ -785,7 +779,7 @@ function Token(type, content, alias, matchedStr) {
*/
Token.stringify = function stringify(o, language) {
if (typeof o == 'string') {
return o;
return _.util.encode(o);
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
}
if (Array.isArray(o)) {
var s = '';
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#line660">line 660</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line654">line 654</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#line675">line 675</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line669">line 669</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#line692">line 692</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line686">line 686</a>
</li></ul></dd>


Expand Down
10 changes: 5 additions & 5 deletions docs/Prism.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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#line601">line 601</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line595">line 595</a>
</li></ul></dd>


Expand Down Expand Up @@ -480,7 +480,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#line448">line 448</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line442">line 442</a>
</li></ul></dd>


Expand Down Expand Up @@ -676,7 +676,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#line467">line 467</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line461">line 461</a>
</li></ul></dd>


Expand Down Expand Up @@ -911,7 +911,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#line513">line 513</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line507">line 507</a>
</li></ul></dd>


Expand Down Expand Up @@ -1157,7 +1157,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#line637">line 637</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line631">line 631</a>
</li></ul></dd>


Expand Down
6 changes: 3 additions & 3 deletions docs/Prism.languages.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#line257">line 257</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line251">line 251</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#line286">line 286</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line280">line 280</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#line371">line 371</a>
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line365">line 365</a>
</li></ul></dd>


Expand Down
Loading