diff --git a/index.js b/index.js index fefc79a..329e38e 100644 --- a/index.js +++ b/index.js @@ -115,7 +115,7 @@ module.exports = function front_matter_plugin(md, cb) { token.hidden = true; token.markup = state.src.slice(startLine, pos); token.block = true; - token.map = [ startLine, pos ]; + token.map = [ startLine, nextLine + (auto_closed ? 1 : 0) ]; token.meta = state.src.slice(start_content, start - 1); state.parentType = old_parent; diff --git a/test/index.js b/test/index.js index 85771eb..f8a990f 100644 --- a/test/index.js +++ b/test/index.js @@ -107,4 +107,33 @@ describe('Markdown It Front Matter', () => { assert.equal(foundFrontmatter, 'x: 1\n---'); }); + + it('Should set correct map for front-matter token', () => { + { + const tokens = md.parse([ + '----', + 'x: 1', + '---', + '# Head' + ].join('\n')); + + assert.strictEqual(tokens[0].type, 'front_matter'); + assert.deepStrictEqual(tokens[0].map, [0, 4]); + } + { + const tokens = md.parse([ + '----', + 'title: Associative arrays', + 'people:', + ' name: John Smith', + ' age: 33', + 'morePeople: { name: Grace Jones, age: 21 }', + '---', + '# Head' + ].join('\n')); + + assert.strictEqual(tokens[0].type, 'front_matter'); + assert.deepStrictEqual(tokens[0].map, [0, 8]); + } + }); });