@@ -22,15 +22,15 @@ public static function OnReset() {}
22
22
23
23
public static function OnEmptyLine ($ context , &$ output ) {$ output = '' ;return false ;}
24
24
25
+ public static function OnNewLine ($ context , &$ output ) {$ output = '' ;return false ;}
26
+
25
27
public static function OnPreBeginLine ($ context , &$ output ) {$ output = '' ;return false ;}
26
28
27
29
public static function OnBeginLine ($ context , &$ output ) {$ output = '' ;return false ;}
28
30
29
31
public static function OnIndent ($ context , &$ output ) {$ output = '' ;return false ;}
30
32
31
- public static function OnUnindent ($ context , &$ output ) {$ output = '' ;return false ;}
32
-
33
- public static function OnUnchangedIndent ($ context , &$ output ) {$ output = '' ;return false ;}
33
+ public static function OnOutdent ($ context , &$ output ) {$ output = '' ;return false ;}
34
34
35
35
public static function OnEndOfDocument ($ context , &$ output ) {$ output = '' ;return false ;}
36
36
}
@@ -354,7 +354,7 @@ public static function OnIndent($context, &$output) {
354
354
return false ;
355
355
}
356
356
357
- public static function OnUnindent ($ context , &$ output ) {
357
+ public static function OnOutdent ($ context , &$ output ) {
358
358
$ output = '' ;
359
359
360
360
// セクションから抜ける前に空行を入れる
@@ -407,6 +407,24 @@ public static function OnEndOfDocument($context, &$output){
407
407
return false ;
408
408
}
409
409
410
+ public static function OnPreBeginLine ($ context , &$ output ){
411
+ $ output = '' ;
412
+
413
+ $ line = $ context ->CurrentLine ();
414
+
415
+ if (preg_match ("/(.*):$/ " , $ line , $ matches )){
416
+ // OnBeginLine で実行
417
+ }
418
+ else {
419
+ if (static ::GetLatestIndent () == $ context ->indentLevel ){
420
+ $ output .= '</dl> ' ;
421
+ array_pop (static ::$ indentStack );
422
+ static ::$ indentStackCount --;
423
+ }
424
+ }
425
+ return false ;
426
+ }
427
+
410
428
public static function OnBeginLine ($ context , &$ output ){
411
429
$ output = '' ;
412
430
@@ -439,11 +457,7 @@ public static function OnBeginLine($context, &$output){
439
457
}
440
458
}
441
459
else {
442
- if (static ::GetLatestIndent () == $ context ->indentLevel ){
443
- $ output .= '</dl> ' ;
444
- array_pop (static ::$ indentStack );
445
- static ::$ indentStackCount --;
446
- }
460
+ // OnPreBeginLine で実行
447
461
}
448
462
return false ;
449
463
}
@@ -463,7 +477,7 @@ public static function OnIndent($context, &$output){
463
477
return false ;
464
478
}
465
479
466
- public static function OnUnindent ($ context , &$ output ){
480
+ public static function OnOutdent ($ context , &$ output ){
467
481
$ output = '' ;
468
482
469
483
if ($ context ->indentLevel == static ::GetLatestIndent ()){
@@ -541,7 +555,7 @@ public static function OnIndent($context, &$output) {
541
555
return false ;
542
556
}
543
557
544
- public static function OnUnindent ($ context , &$ output ) {
558
+ public static function OnOutdent ($ context , &$ output ) {
545
559
$ output = '' ;
546
560
547
561
$ currentChunk = $ context ->CurrentChunk ();
@@ -563,6 +577,37 @@ public static function OnUnindent($context, &$output) {
563
577
return false ;
564
578
}
565
579
580
+ public static function OnPreBeginLine ($ context , &$ output ){
581
+ $ output = '' ;
582
+
583
+ $ currentChunk = $ context ->CurrentChunk ();
584
+
585
+ if (static ::$ listStackCount <= 0 ){
586
+ // OnBeginLine で実行
587
+ }
588
+ elseif (
589
+ ($ list = static ::GetLatestList ()) !== false &&
590
+ $ list ['indentLevel ' ] == $ currentChunk ['indentLevel ' ]
591
+ ){
592
+ if (
593
+ preg_match ("/^\* / " , $ currentChunk ["content " ]) ||
594
+ preg_match ("/^\+ / " , $ currentChunk ["content " ]) ||
595
+ preg_match ("/^([a-zA-Z0-9]+\.)+ / " , $ currentChunk ["content " ])
596
+ ){
597
+ // OnBeginLine で実行
598
+ }
599
+ else {
600
+ // このレベルのリスト終了
601
+ $ list = array_pop (static ::$ listStack );
602
+ static ::$ listStackCount --;
603
+
604
+ $ output .= '</li> ' . $ list ['endTag ' ];
605
+ return false ;
606
+ }
607
+ }
608
+ return false ;
609
+ }
610
+
566
611
public static function OnBeginLine ($ context , &$ output ) {
567
612
$ output = '' ;
568
613
@@ -596,12 +641,7 @@ public static function OnBeginLine($context, &$output) {
596
641
return true ;
597
642
}
598
643
else {
599
- // このレベルのリスト終了
600
- $ list = array_pop (static ::$ listStack );
601
- static ::$ listStackCount --;
602
-
603
- $ output .= '</li> ' . $ list ['endTag ' ];
604
- return false ;
644
+ // OnPreBeginLineで実行
605
645
}
606
646
}
607
647
elseif (
@@ -714,7 +754,7 @@ public static function OnEmptyLine($context, &$output) {
714
754
return false ;
715
755
}
716
756
717
- public static function OnPreBeginLine ($ context , &$ output ) {
757
+ public static function OnNewLine ($ context , &$ output ) {
718
758
$ output = '' ;
719
759
720
760
if (static ::$ isBeginRow ) {
@@ -852,6 +892,7 @@ private static function IsTableLine($context) {
852
892
class HeadingElementParser extends ElementParser {
853
893
private static $ isBegin = false ;
854
894
private static $ heading = '' ;
895
+ private static $ level ;
855
896
private static $ nextLineIsHorizontalLine = false ;
856
897
857
898
public static function OnReset () {
@@ -862,18 +903,18 @@ public static function OnEmptyLine($context, &$output) {
862
903
$ output = '' ;
863
904
864
905
if (static ::$ isBegin ) {
865
- $ output .= '</h ' . ( $ context -> indentLevel + 2 ) . '> ' ;
906
+ $ output .= '</h ' . static :: $ level . '> ' ;
866
907
static ::$ isBegin = false ;
867
908
}
868
909
869
910
return false ;
870
911
}
871
912
872
- public static function OnPreBeginLine ($ context , &$ output ) {
913
+ public static function OnNewLine ($ context , &$ output ) {
873
914
$ output = '' ;
874
915
875
916
if (static ::$ isBegin ) {
876
- $ output .= '</h ' . ( $ context -> indentLevel + 2 ) . '> ' ;
917
+ $ output .= '</h ' . static :: $ level . '> ' ;
877
918
static ::$ isBegin = false ;
878
919
}
879
920
@@ -884,17 +925,8 @@ public static function OnBeginLine($context, &$output) {
884
925
$ output = '' ;
885
926
886
927
if (static ::IsHeadingLine ($ context )) {
887
- $ output .= '<h ' . ($ context ->indentLevel + 2 ) . '> ' ;
888
- // if ($context->indentLevel <= 0) {
889
- // $output .= "class = 'section-title'>";
890
- // } elseif ($context->indentLevel == 1) {
891
- // $output .= "class = 'sub-section-title'>";
892
- // } elseif ($context->indentLevel == 2) {
893
- // $output .= "class = 'sub-sub-section-title'>";
894
- // } else {
895
- // $output .= "class = 'sub-sub-sub-section-title'>";
896
- // }
897
-
928
+ static ::$ level = $ context ->indentLevel + 2 ;
929
+ $ output .= '<h ' . static ::$ level . '> ' ;
898
930
$ output .= Parser::DecodeSpanElements (static ::$ heading , $ context );
899
931
900
932
if (static ::$ nextLineIsHorizontalLine ) {
@@ -1169,17 +1201,21 @@ class Parser {
1169
1201
'DefinitionListElementParser ' ,
1170
1202
];
1171
1203
1172
- private static $ onPreBeginLineParserList = [
1204
+ private static $ onNewLineParserList = [
1173
1205
'HeadingElementParser ' ,
1174
- 'BoxElementParser ' ,
1175
1206
'TableElementParser ' ,
1207
+ ];
1208
+
1209
+ private static $ onPreBeginLineParserList = [
1176
1210
'ListElementParser ' ,
1211
+ 'DefinitionListElementParser ' ,
1212
+ 'BoxElementParser ' ,
1177
1213
];
1178
1214
1179
1215
private static $ onBeginLineParserList = [
1180
- 'HeadingElementParser ' ,
1181
- 'DefinitionListElementParser ' ,
1182
1216
'ListElementParser ' ,
1217
+ 'DefinitionListElementParser ' ,
1218
+ 'HeadingElementParser ' ,
1183
1219
'BoxElementParser ' ,
1184
1220
'BlockquoteElementParser ' ,
1185
1221
'HorizontalLineElementParser ' ,
@@ -1206,16 +1242,12 @@ class Parser {
1206
1242
'SectionElementParser ' ,
1207
1243
];
1208
1244
1209
- private static $ onUnindentParserList = [
1245
+ private static $ onOutdentParserList = [
1210
1246
'ListElementParser ' , // // 順番大事. List -> Definition
1211
1247
'DefinitionListElementParser ' ,
1212
1248
'SectionElementParser ' ,
1213
1249
];
1214
1250
1215
- private static $ onUnchangedIndentParserList = [
1216
- // 'ListElementParser',
1217
- ];
1218
-
1219
1251
private static $ onEndOfDocumentParserList = [
1220
1252
'ListElementParser ' ,
1221
1253
'DefinitionListElementParser ' ,
@@ -1250,12 +1282,12 @@ class Parser {
1250
1282
// End Parser Configuration ===
1251
1283
1252
1284
public static $ onResetParserFuncList = [];
1285
+ public static $ onEmptyLineParserFuncList = [];
1286
+ public static $ onNewLineParserFuncList = [];
1253
1287
public static $ onPreBeginLineParserFuncList = [];
1254
1288
public static $ onBeginLineParserFuncList = [];
1255
- public static $ onEmptyLineParserFuncList = [];
1256
1289
public static $ onIndentParserFuncList = [];
1257
- public static $ onUnindentParserFuncList = [];
1258
- public static $ onUnchangedIndentParserFuncList = [];
1290
+ public static $ onOutdentParserFuncList = [];
1259
1291
public static $ onEndOfDocumentParserFuncList = [];
1260
1292
1261
1293
private static $ blockSeparatorsPattern ;
@@ -1311,26 +1343,26 @@ public static function Init() {
1311
1343
static ::$ nonVoidHtmlEndTagsPattern = '/ ' . static ::$ nonVoidHtmlEndTagsPattern . '/i ' ;
1312
1344
static ::$ voidHtmlTagsPattern = '/ ' . static ::$ voidHtmlTagsPattern . '/i ' ;
1313
1345
1314
- foreach (static ::$ onBeginLineParserList as $ parser ) {
1315
- static ::$ onBeginLineParserFuncList [] = ['OutlineText \\' . $ parser , 'OnBeginLine ' ];
1346
+ foreach (static ::$ onEmptyLineParserList as $ parser ) {
1347
+ static ::$ onEmptyLineParserFuncList [] = ['OutlineText \\' . $ parser , 'OnEmptyLine ' ];
1348
+ }
1349
+ foreach (static ::$ onNewLineParserList as $ parser ) {
1350
+ static ::$ onNewLineParserFuncList [] = ['OutlineText \\' . $ parser , 'OnNewLine ' ];
1316
1351
}
1317
1352
foreach (static ::$ onPreBeginLineParserList as $ parser ) {
1318
1353
static ::$ onPreBeginLineParserFuncList [] = ['OutlineText \\' . $ parser , 'OnPreBeginLine ' ];
1319
1354
}
1320
- foreach (static ::$ onEmptyLineParserList as $ parser ) {
1321
- static ::$ onEmptyLineParserFuncList [] = ['OutlineText \\' . $ parser , 'OnEmptyLine ' ];
1355
+ foreach (static ::$ onBeginLineParserList as $ parser ) {
1356
+ static ::$ onBeginLineParserFuncList [] = ['OutlineText \\' . $ parser , 'OnBeginLine ' ];
1322
1357
}
1323
1358
foreach (static ::$ onResetParserList as $ parser ) {
1324
1359
static ::$ onResetParserFuncList [] = ['OutlineText \\' . $ parser , 'OnReset ' ];
1325
1360
}
1326
1361
foreach (static ::$ onIndentParserList as $ parser ) {
1327
1362
static ::$ onIndentParserFuncList [] = ['OutlineText \\' . $ parser , 'OnIndent ' ];
1328
1363
}
1329
- foreach (static ::$ onUnindentParserList as $ parser ) {
1330
- static ::$ onUnindentParserFuncList [] = ['OutlineText \\' . $ parser , 'OnUnindent ' ];
1331
- }
1332
- foreach (static ::$ onUnchangedIndentParserList as $ parser ) {
1333
- static ::$ onUnchangedIndentParserFuncList [] = ['OutlineText \\' . $ parser , 'OnUnchangedIndent ' ];
1364
+ foreach (static ::$ onOutdentParserList as $ parser ) {
1365
+ static ::$ onOutdentParserFuncList [] = ['OutlineText \\' . $ parser , 'OnOutdent ' ];
1334
1366
}
1335
1367
foreach (static ::$ onEndOfDocumentParserList as $ parser ) {
1336
1368
static ::$ onEndOfDocumentParserFuncList [] = ['OutlineText \\' . $ parser , 'OnEndOfDocument ' ];
@@ -1405,8 +1437,8 @@ public static function Parse($plainText, &$context = null) {
1405
1437
continue ;
1406
1438
}
1407
1439
1408
- // 行頭の前処理
1409
- $ output .= static ::CallbackEventFuncs (static ::$ onPreBeginLineParserFuncList , $ context );
1440
+ // 新しい行が始まった
1441
+ $ output .= static ::CallbackEventFuncs (static ::$ onNewLineParserFuncList , $ context );
1410
1442
1411
1443
//
1412
1444
// --- インデントレベルの変化を見る ----------------------
@@ -1422,20 +1454,15 @@ public static function Parse($plainText, &$context = null) {
1422
1454
// 左へインデント
1423
1455
if ($ currentChunk ["indentLevel " ] < $ context ->indentLevelPrevious ) {
1424
1456
while ($ currentChunk ["indentLevel " ] < $ context ->indentLevel ) {
1425
- $ output .= static ::CallbackEventFuncs (static ::$ onUnindentParserFuncList , $ context );
1457
+ $ output .= static ::CallbackEventFuncs (static ::$ onOutdentParserFuncList , $ context );
1426
1458
$ context ->indentLevel --;
1427
1459
}
1428
1460
}
1429
1461
1430
- // インデントそのまま
1431
- if ($ currentChunk ["indentLevel " ] == $ context ->indentLevelPrevious ) {
1432
- $ output .= static ::CallbackEventFuncs (static ::$ onUnchangedIndentParserFuncList , $ context );
1433
- }
1434
-
1435
1462
$ context ->indentLevelPrevious = $ context ->indentLevel ;
1436
1463
1437
1464
// End インデントの変化を見る ---
1438
-
1465
+
1439
1466
// 空文字の時
1440
1467
// インデント値はあるが, 空文字
1441
1468
// その次がインラインコード, html要素のときに起こる.
@@ -1457,14 +1484,17 @@ public static function Parse($plainText, &$context = null) {
1457
1484
//continue;
1458
1485
}
1459
1486
1487
+ // 行頭の前処理
1488
+ $ output .= static ::CallbackEventFuncs (static ::$ onPreBeginLineParserFuncList , $ context );
1489
+
1460
1490
// 行頭の処理
1461
1491
$ output .= static ::CallbackEventFuncs (static ::$ onBeginLineParserFuncList , $ context );
1462
1492
1463
1493
} // End 各チャンクごとに対して ----
1464
1494
1465
1495
// すべてのチャンクの処理を終えた場合
1466
1496
while (0 < $ context ->indentLevel ){
1467
- $ output .= static ::CallbackEventFuncs (static ::$ onUnindentParserFuncList , $ context );
1497
+ $ output .= static ::CallbackEventFuncs (static ::$ onOutdentParserFuncList , $ context );
1468
1498
$ context ->indentLevel --;
1469
1499
}
1470
1500
$ context ->indentLevelPrevious = $ context ->indentLevel ;
0 commit comments