1
1
import { builders } from 'prosemirror-test-builder' ;
2
+ import dd from 'ts-dedent' ;
2
3
3
4
import { parseDOM } from '../../../../tests/parse-dom' ;
4
5
import { createMarkupChecker } from '../../../../tests/sameMarkup' ;
@@ -73,21 +74,21 @@ describe('Heading extension', () => {
73
74
} ) ;
74
75
75
76
it ( 'should parse few headings' , ( ) => {
76
- const markup = `
77
- # h1 {#one}
77
+ const markup = dd `
78
+ # h1 {#one}
78
79
79
- ## h2 {#two}
80
+ ## h2 {#two}
80
81
81
- ### h3 {#three}
82
+ ### h3 {#three}
82
83
83
- #### h4 {#four}
84
+ #### h4 {#four}
84
85
85
- ##### h5 {#five}
86
+ ##### h5 {#five}
86
87
87
- ###### h6 {#six}
88
+ ###### h6 {#six}
88
89
89
- para
90
- ` . trim ( ) ;
90
+ para
91
+ `. trim ( ) ;
91
92
92
93
same (
93
94
markup ,
@@ -103,6 +104,59 @@ para
103
104
) ;
104
105
} ) ;
105
106
107
+ it ( 'should parse headings with id without markdown-it-attrs' , ( ) => {
108
+ const markup = dd `
109
+ # h1 {#one}
110
+
111
+ ## h2 {#two}
112
+
113
+ ### h3 {#three}
114
+
115
+ #### h4 {#four}
116
+
117
+ ##### h5 {#five}
118
+
119
+ ###### h6 {#six}
120
+
121
+ para
122
+ ` . trim ( ) ;
123
+
124
+ const {
125
+ schema,
126
+ markupParser : parser ,
127
+ serializer,
128
+ } = new ExtensionsManager ( {
129
+ extensions : ( builder ) =>
130
+ builder
131
+ . use ( BaseSchemaSpecs , { } )
132
+ . use ( YfmConfigsSpecs , { disableAttrs : true } )
133
+ . use ( YfmHeadingSpecs , { } ) ,
134
+ } ) . buildDeps ( ) ;
135
+ const { same} = createMarkupChecker ( { parser, serializer} ) ;
136
+
137
+ const { doc, p, h} = builders <
138
+ 'doc' | 'p' | 'h' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' ,
139
+ 'b'
140
+ > ( schema , {
141
+ doc : { nodeType : BaseNode . Doc } ,
142
+ p : { nodeType : BaseNode . Paragraph } ,
143
+ h : { nodeType : headingNodeName } ,
144
+ } ) ;
145
+
146
+ same (
147
+ markup ,
148
+ doc (
149
+ h ( { [ YfmHeadingAttr . Level ] : 1 , [ YfmHeadingAttr . Id ] : 'one' } , 'h1' ) ,
150
+ h ( { [ YfmHeadingAttr . Level ] : 2 , [ YfmHeadingAttr . Id ] : 'two' } , 'h2' ) ,
151
+ h ( { [ YfmHeadingAttr . Level ] : 3 , [ YfmHeadingAttr . Id ] : 'three' } , 'h3' ) ,
152
+ h ( { [ YfmHeadingAttr . Level ] : 4 , [ YfmHeadingAttr . Id ] : 'four' } , 'h4' ) ,
153
+ h ( { [ YfmHeadingAttr . Level ] : 5 , [ YfmHeadingAttr . Id ] : 'five' } , 'h5' ) ,
154
+ h ( { [ YfmHeadingAttr . Level ] : 6 , [ YfmHeadingAttr . Id ] : 'six' } , 'h6' ) ,
155
+ p ( 'para' ) ,
156
+ ) ,
157
+ ) ;
158
+ } ) ;
159
+
106
160
it . each ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ( 'should parse html - h%s tag' , ( lvl ) => {
107
161
parseDOM (
108
162
schema ,
0 commit comments