Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix token.map #20

Merged
merged 3 commits into from Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/index.js
Expand Up @@ -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]);
}
});
});