File tree 2 files changed +26
-6
lines changed
2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -34,25 +34,33 @@ function tokenize(str) {
34
34
// 空文字は無視します
35
35
if ( str . length === 0 ) { return tokens ; }
36
36
37
- var isCGMD = false ;
37
+ var isCGMD = null ; // or note, column, imgbox, ...
38
38
// 全ての行をなめる
39
39
while ( ( line = lines . shift ( ) ) !== undefined ) {
40
40
// CGMDのスタート / エンドでフラグを打つ
41
41
if ( CGMD_START_RE . exec ( line ) ) {
42
- isCGMD = true ;
42
+ // ネストしようとした
43
+ if ( isCGMD !== null )
44
+ throw new Error ( `[${ isCGMD } ] is still opened, nesting is not allowed!` ) ;
45
+
46
+ isCGMD = line . slice ( 1 , - 1 ) ;
43
47
tokens . push ( new CGMD_Token ( ) ) ;
44
48
tokens [ tokens . length - 1 ] . addBody ( line ) ;
45
49
continue ;
46
50
}
47
51
if ( CGMD_END_RE . exec ( line ) ) {
48
- isCGMD = false ;
52
+ // 異なる種類で閉じようとした
53
+ if ( isCGMD !== line . slice ( 2 , - 1 ) )
54
+ throw new Error ( `[${ isCGMD } ] should not be closed by ${ line } !` ) ;
55
+
56
+ isCGMD = null ;
49
57
tokens [ tokens . length - 1 ] . addBody ( line ) ;
50
58
continue ;
51
59
}
52
60
53
61
if (
54
62
// ふつうのMDでありつつ
55
- isCGMD === false &&
63
+ isCGMD === null &&
56
64
(
57
65
// 最初か
58
66
tokens . length === 0 ||
@@ -69,8 +77,8 @@ function tokenize(str) {
69
77
}
70
78
71
79
// 全行見終わってまだこのフラグが立ってるなら閉じ忘れ
72
- if ( isCGMD ) {
73
- throw new Error ( ' Missing close tag for CGMD!' ) ;
80
+ if ( isCGMD !== null ) {
81
+ throw new Error ( ` Missing close tag for [ ${ isCGMD } ]!` ) ;
74
82
}
75
83
76
84
return tokens ;
Original file line number Diff line number Diff line change @@ -43,6 +43,18 @@ describe('#tokenize', function() {
43
43
} ) ;
44
44
} ) ;
45
45
46
+ it ( 'cgmdネストもエラー' , function ( ) {
47
+ assert . throws ( function ( ) {
48
+ Tokenizer . tokenize ( '[demo]\n# Nesting not allowed!\n[imgbox]' ) ;
49
+ } ) ;
50
+ } ) ;
51
+
52
+ it ( 'cgmd違うので閉じるとエラー' , function ( ) {
53
+ assert . throws ( function ( ) {
54
+ Tokenizer . tokenize ( '[imgbox]\n# Wrong closing!\n[/column]' ) ;
55
+ } ) ;
56
+ } ) ;
57
+
46
58
it ( 'cgmdの規定のタイプ以外は無視' , function ( ) {
47
59
var tokens = Tokenizer . tokenize ( [
48
60
'```toml' ,
You can’t perform that action at this time.
0 commit comments