Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit fd4558d

Browse files
author
mikesamuel
committed
fixed styling for unclosed token or line comment at end of a node.
1 parent dcf522b commit fd4558d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/prettify.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function PR_attribToHtml(str) {
245245
return str.replace(/&/g, '&')
246246
.replace(/</g, '&lt;')
247247
.replace(/>/g, '&gt;')
248-
.replace(/"/g, '&quot;')
248+
.replace(/\"/g, '&quot;')
249249
.replace(/\xa0/, '&nbsp;');
250250
}
251251

@@ -730,7 +730,20 @@ function PR_splitStringAndCommentTokens(chunks) {
730730
}
731731
k += s.length;
732732
}
733-
tokenEnds.push(new PR_TokenEnd(k, PR_PLAIN)); // a token ends at the end
733+
var endTokenType;
734+
switch (state) {
735+
case 1: case 2:
736+
endTokenType = PR_STRING;
737+
break;
738+
case 4: case 5: case 6:
739+
endTokenType = PR_COMMENT;
740+
break;
741+
default:
742+
endTokenType = PR_PLAIN;
743+
break;
744+
}
745+
// handle unclosed token which can legally happen for line comments (state 4)
746+
tokenEnds.push(new PR_TokenEnd(k, endTokenType)); // a token ends at the end
734747

735748
return PR_splitChunks(chunks, tokenEnds);
736749
}

tests/prettify_test.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ <h1>HTML using XMP</h1>
293293
<h1>Whitespace</h1>
294294
<pre class=prettyprint id="whitespace"></pre>
295295

296+
<h1>Misc</h1>
297+
<pre class=prettyprint id="misc1">// ends with line comment token
298+
//</pre>
299+
296300
</body>
297301

298302
<script type="text/javascript">
@@ -662,7 +666,9 @@ <h1>Whitespace</h1>
662666
'&nbsp; &nbsp; `END`END`TAG&lt;/script&gt;`END`PLN<br>' +
663667
'&nbsp; `END`TAG&lt;/body&gt;`END`PLN<br>' +
664668
'`END`TAG&lt;/html&gt;`END'),
665-
whitespace: ''
669+
whitespace: '',
670+
misc1: '`COM// ends with line comment token`END`PLN<br>' +
671+
'`END`COM//`END'
666672
};
667673

668674

0 commit comments

Comments
 (0)