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

Incorrect closing sourcepos column for code blocks #141

Closed
oampo opened this issue May 29, 2018 · 2 comments
Closed

Incorrect closing sourcepos column for code blocks #141

oampo opened this issue May 29, 2018 · 2 comments

Comments

@oampo
Copy link

oampo commented May 29, 2018

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.

@SonyaOrlova
Copy link

SonyaOrlova commented Sep 24, 2019

i have the same problem with comments (html_block)
example:

# Example
<!-- this is a comment -->

for the comment i expect to see the following sourcepos [2, 1] [2, 26], but i get [2, 1] [2, 9]

adding this.lastLineLength = ln.length; before this.finalize here

this.finalize(container, this.lineNumber);
solves the problem

and one more interesting thing: if i add several spaces before comment, like this:

# Example
    <!-- this is a comment -->

i get code_block type instead of html_block, and correct sourcepos

@jgm jgm closed this as completed in 1f5a827 Jan 9, 2020
@jgm
Copy link
Member

jgm commented Jan 9, 2020

Thanks for reporting!

jgm added a commit that referenced this issue Jan 9, 2020
Improves on earlier fix to #141, which only worked for code blocks
flush with the left margin.
taku0 added a commit to taku0/cmark-el that referenced this issue Jan 11, 2020
Closes commonmark/commonmark.js#141.

commonmark/commonmark.js@1f5a827
Author: John MacFarlane <jgm@berkeley.edu>
Date:   Thu Jan 9 08:38:20 2020 -0800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants