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.
The
sourceposattribute for code blocks reports the column number for the line before the end of the block.Here's a quick test case:
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 thehello worldline before the closing backticks.