@@ -119,6 +119,9 @@ public static bool DisableBehaviorTagP
119
119
/// </summary>
120
120
public bool OptionEmptyCollection = false ;
121
121
122
+ /// <summary>True of the whole <![CDATA[ block should be threated as a single comment.</summary>
123
+ public bool OptionThreatCDataBlockAsComment ;
124
+
122
125
/// <summary>True to disable, false to enable the server side code.</summary>
123
126
public bool DisableServerSideCode = false ;
124
127
@@ -1294,24 +1297,38 @@ private bool NewCheck()
1294
1297
{
1295
1298
if ( Text [ _index ] == '!' || Text [ _index ] == '?' )
1296
1299
{
1297
- PushNodeStart ( HtmlNodeType . Comment , _index - 1 , _lineposition - 1 ) ;
1298
- PushNodeNameStart ( true , _index ) ;
1299
- PushNodeNameEnd ( _index + 1 ) ;
1300
- _state = ParseState . Comment ;
1301
- if ( _index < ( Text . Length - 2 ) )
1300
+ if ( OptionThreatCDataBlockAsComment && Text . Substring ( _index ) . StartsWith ( "![CDATA[" , StringComparison . OrdinalIgnoreCase ) )
1302
1301
{
1303
- if ( ( Text [ _index + 1 ] == '-' ) &&
1304
- ( Text [ _index + 2 ] == '-' ) )
1302
+ PushNodeStart ( HtmlNodeType . Comment , _index - 1 , _lineposition - 1 ) ;
1303
+ PushNodeNameStart ( true , _index ) ;
1304
+ PushNodeNameEnd ( _index + 1 ) ;
1305
+
1306
+ _state = ParseState . PcDataComment ;
1307
+
1308
+ return true ;
1309
+ }
1310
+ else
1311
+ {
1312
+ PushNodeStart ( HtmlNodeType . Comment , _index - 1 , _lineposition - 1 ) ;
1313
+ PushNodeNameStart ( true , _index ) ;
1314
+ PushNodeNameEnd ( _index + 1 ) ;
1315
+
1316
+ _state = ParseState . Comment ;
1317
+ if ( _index < ( Text . Length - 2 ) )
1305
1318
{
1306
- _fullcomment = true ;
1319
+ if ( ( Text [ _index + 1 ] == '-' ) &&
1320
+ ( Text [ _index + 2 ] == '-' ) )
1321
+ {
1322
+ _fullcomment = true ;
1323
+ }
1324
+ else
1325
+ {
1326
+ _fullcomment = false ;
1327
+ }
1307
1328
}
1308
- else
1309
- {
1310
- _fullcomment = false ;
1311
- }
1312
- }
1313
1329
1314
- return true ;
1330
+ return true ;
1331
+ }
1315
1332
}
1316
1333
}
1317
1334
@@ -1355,6 +1372,9 @@ private void Parse()
1355
1372
while ( _index < Text . Length )
1356
1373
{
1357
1374
_c = Text [ _index ] ;
1375
+ #if DEBUG
1376
+ char _cChar = Text [ _index ] ;
1377
+ #endif
1358
1378
IncrementPosition ( ) ;
1359
1379
1360
1380
switch ( _state )
@@ -1702,6 +1722,23 @@ private void Parse()
1702
1722
1703
1723
break ;
1704
1724
1725
+ case ParseState . PcDataComment :
1726
+ if ( _c == '>' && _index < Text . Length && Text [ _index - 3 ] == ']' && Text [ _index - 2 ] == ']' )
1727
+ {
1728
+ if ( ! PushNodeEnd ( _index , false ) )
1729
+ {
1730
+ // stop parsing
1731
+ _index = Text . Length ;
1732
+ break ;
1733
+ }
1734
+
1735
+ _state = ParseState . Text ;
1736
+ PushNodeStart ( HtmlNodeType . Text , _index , _lineposition ) ;
1737
+ continue ;
1738
+ }
1739
+
1740
+ break ;
1741
+
1705
1742
case ParseState . ServerSideCode :
1706
1743
if ( _c == '%' )
1707
1744
{
@@ -2227,7 +2264,7 @@ private void ReadDocumentEncoding(HtmlNode node)
2227
2264
}
2228
2265
}
2229
2266
2230
- #endregion
2267
+ #endregion
2231
2268
2232
2269
#region Nested type: ParseState
2233
2270
@@ -2245,7 +2282,8 @@ private enum ParseState
2245
2282
Comment ,
2246
2283
QuotedAttributeValue ,
2247
2284
ServerSideCode ,
2248
- PcData
2285
+ PcData ,
2286
+ PcDataComment
2249
2287
}
2250
2288
2251
2289
#endregion
0 commit comments