|
| 1 | +import Tokenizer from '..'; |
| 2 | + |
| 3 | +describe('MarkdownIt Comments plugin', function () { |
| 4 | + const tokenizer = new Tokenizer({ allowComments: true }); |
| 5 | + |
| 6 | + function parse(example) { |
| 7 | + const content = example.replace(/\n\s+/gm, '\n').trim(); |
| 8 | + return tokenizer.tokenize(content); |
| 9 | + } |
| 10 | + |
| 11 | + describe('inline comments', function () { |
| 12 | + const output = [ |
| 13 | + { type: 'paragraph_open' }, |
| 14 | + { |
| 15 | + type: 'inline', |
| 16 | + children: [ |
| 17 | + { type: 'text', content: 'this is a test ' }, |
| 18 | + { type: 'comment', content: 'example comment' }, |
| 19 | + { type: 'text', content: ' foo' }, |
| 20 | + ], |
| 21 | + }, |
| 22 | + { type: 'paragraph_close' }, |
| 23 | + ]; |
| 24 | + |
| 25 | + it('simple inline comment', function () { |
| 26 | + const example = parse(` |
| 27 | + this is a test <!-- example comment --> foo |
| 28 | + `); |
| 29 | + |
| 30 | + expect(example).toDeepEqualSubset(output); |
| 31 | + }); |
| 32 | + |
| 33 | + it('inline comment with a newline', function () { |
| 34 | + const example = parse(` |
| 35 | + this is a test <!-- |
| 36 | + example comment |
| 37 | + --> foo |
| 38 | + `); |
| 39 | + |
| 40 | + expect(example).toDeepEqualSubset(output); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('block comments', function () { |
| 45 | + const output = [ |
| 46 | + { type: 'paragraph_open' }, |
| 47 | + { type: 'inline' }, |
| 48 | + { type: 'paragraph_close' }, |
| 49 | + { type: 'comment', content: 'example comment' }, |
| 50 | + { type: 'paragraph_open' }, |
| 51 | + { type: 'inline', content: 'foo' }, |
| 52 | + { type: 'paragraph_close' }, |
| 53 | + ]; |
| 54 | + |
| 55 | + it('simple block comment after a paragraph', function () { |
| 56 | + const example = parse(` |
| 57 | + this is a test |
| 58 | +
|
| 59 | + <!-- |
| 60 | + example comment |
| 61 | + --> |
| 62 | + |
| 63 | + foo |
| 64 | + `); |
| 65 | + |
| 66 | + expect(example).toDeepEqualSubset(output); |
| 67 | + }); |
| 68 | + |
| 69 | + it('block comment with ending on same line as content', function () { |
| 70 | + const example = parse(` |
| 71 | + this is a test |
| 72 | +
|
| 73 | + <!-- |
| 74 | + example comment --> |
| 75 | +
|
| 76 | + foo |
| 77 | + `); |
| 78 | + |
| 79 | + expect(example).toDeepEqualSubset(output); |
| 80 | + }); |
| 81 | + |
| 82 | + it('block comment one one line', function () { |
| 83 | + const example = parse(` |
| 84 | + this is a test |
| 85 | +
|
| 86 | + <!-- example comment --> |
| 87 | +
|
| 88 | + foo |
| 89 | + `); |
| 90 | + |
| 91 | + expect(example).toDeepEqualSubset(output); |
| 92 | + }); |
| 93 | + }); |
| 94 | +}); |
0 commit comments