|
| 1 | +import {builders} from 'prosemirror-test-builder'; |
| 2 | + |
| 3 | +import {createMarkupChecker} from '../../../../../tests/sameMarkup'; |
| 4 | +import {ExtensionsManager} from '../../../../core'; |
| 5 | +import {BaseNode, BaseSchemaSpecs} from '../../../base/specs'; |
| 6 | +import {ItalicSpecs, headingNodeName, italicMarkName} from '../../../markdown/specs'; |
| 7 | +import {YfmHeadingAttr, YfmHeadingSpecs} from '../../../yfm/specs'; |
| 8 | + |
| 9 | +import {FoldingHeadingSpecs} from './FoldingHeadingSpecs'; |
| 10 | + |
| 11 | +const {schema, markupParser, serializer} = new ExtensionsManager({ |
| 12 | + extensions: (builder) => |
| 13 | + builder |
| 14 | + .use(BaseSchemaSpecs, {}) |
| 15 | + .use(ItalicSpecs) |
| 16 | + .use(YfmHeadingSpecs, {}) |
| 17 | + .use(FoldingHeadingSpecs), |
| 18 | +}).buildDeps(); |
| 19 | + |
| 20 | +const {doc, h1, h2, h3, h4, h5, h6, i} = builders< |
| 21 | + 'doc' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6', |
| 22 | + 'i' |
| 23 | +>(schema, { |
| 24 | + doc: {nodeType: BaseNode.Doc}, |
| 25 | + h1: {nodeType: headingNodeName, [YfmHeadingAttr.Level]: 1}, |
| 26 | + h2: {nodeType: headingNodeName, [YfmHeadingAttr.Level]: 2}, |
| 27 | + h3: {nodeType: headingNodeName, [YfmHeadingAttr.Level]: 3}, |
| 28 | + h4: {nodeType: headingNodeName, [YfmHeadingAttr.Level]: 4}, |
| 29 | + h5: {nodeType: headingNodeName, [YfmHeadingAttr.Level]: 5}, |
| 30 | + h6: {nodeType: headingNodeName, [YfmHeadingAttr.Level]: 6}, |
| 31 | + i: {markType: italicMarkName}, |
| 32 | +}); |
| 33 | + |
| 34 | +const {same} = createMarkupChecker({parser: markupParser, serializer}); |
| 35 | + |
| 36 | +describe('Folding Headings', () => { |
| 37 | + it('should parse folding headings', () => { |
| 38 | + const markup = ` |
| 39 | +#+ heading 1 |
| 40 | +
|
| 41 | +##+ heading 2 |
| 42 | +
|
| 43 | +###+ heading 3 |
| 44 | +
|
| 45 | +####+ heading 4 |
| 46 | +
|
| 47 | +#####+ heading 5 |
| 48 | +
|
| 49 | +######+ heading 6 |
| 50 | +`.trim(); |
| 51 | + |
| 52 | + return same( |
| 53 | + markup, |
| 54 | + doc( |
| 55 | + h1({[YfmHeadingAttr.Folding]: true}, 'heading 1'), |
| 56 | + h2({[YfmHeadingAttr.Folding]: true}, 'heading 2'), |
| 57 | + h3({[YfmHeadingAttr.Folding]: true}, 'heading 3'), |
| 58 | + h4({[YfmHeadingAttr.Folding]: true}, 'heading 4'), |
| 59 | + h5({[YfmHeadingAttr.Folding]: true}, 'heading 5'), |
| 60 | + h6({[YfmHeadingAttr.Folding]: true}, 'heading 6'), |
| 61 | + ), |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should parse common headings', () => { |
| 66 | + const markup = ` |
| 67 | +# heading 1 |
| 68 | +
|
| 69 | +## heading 2 |
| 70 | +
|
| 71 | +### heading 3 |
| 72 | +
|
| 73 | +#### heading 4 |
| 74 | +
|
| 75 | +##### heading 5 |
| 76 | +
|
| 77 | +###### heading 6 |
| 78 | +`.trim(); |
| 79 | + |
| 80 | + return same( |
| 81 | + markup, |
| 82 | + doc( |
| 83 | + h1('heading 1'), |
| 84 | + h2('heading 2'), |
| 85 | + h3('heading 3'), |
| 86 | + h4('heading 4'), |
| 87 | + h5('heading 5'), |
| 88 | + h6('heading 6'), |
| 89 | + ), |
| 90 | + ); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should parse folding heading with inline markup', () => { |
| 94 | + const markup = ` |
| 95 | +##+ *heading* 2 |
| 96 | +`.trim(); |
| 97 | + |
| 98 | + return same(markup, doc(h2({[YfmHeadingAttr.Folding]: true}, i('heading'), ' 2'))); |
| 99 | + }); |
| 100 | +}); |
0 commit comments