Skip to content

Incorrect closing sourcepos column for code blocks  #141

@oampo

Description

@oampo

The sourcepos attribute for code blocks reports the column number for the line before the end of the block.

Here's a quick test case:

const commonmark = require('commonmark');
const parser = new commonmark.Parser();

// Annotated with line numbers
// 1 ```
// 2 hello world
// 3 ```
const md = '```\nhello world\n```';

const node = parser.parse(md);

const walker = node.walker();

while ((event = walker.next())) {
    const {node} = event;
    if (node.type === 'code_block') {
        console.log(node.sourcepos);
    }
}

I'd expect to see [[1, 1], [3, 3]] - the backticks start at L1C1 and end at L3C3. Instead, I see [[1, 1], [3, 11]], where the closing column number (11) is the length of the hello world line before the closing backticks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions