CommonMark.NET icon indicating copy to clipboard operation
CommonMark.NET copied to clipboard

Keep StartLine/EndLine/StartColumn

Open dmitry-shechtman opened this issue 10 years ago • 9 comments

Hi,

I'm using CommonMark.NET for parsing.

I have a converter on top of it, which should present warnings like

invalid link target on line {0} position {1}

I don't think that would be possible with just SourcePosition and SourceLength.

dmitry-shechtman avatar Nov 24 '15 03:11 dmitry-shechtman

It would be possible, you would just have to count the newlines that are before the SourcePosition.

In fact StartLine and StartColumn does not suit this purpose as it only points to the start of the block (for example, paragraph). Since you would need the position of the link itself (as there could be multiple links within the same block) you would have to use SourcePosition.

Knagis avatar Nov 24 '15 09:11 Knagis

How would I count the newlines?

Wouldn't it be easier for me to add StartLine and StartPosition to Inline?

dmitry-shechtman avatar Nov 24 '15 10:11 dmitry-shechtman

You can try though I would not suggest it. :) It will be easier to use string.IndexOf('\n', previousIndex) to count the newlines up to the StartPosition in the source string.

If you are using streams, it will be harder - in this case perhaps you could add the line counter to the parser - it could be a List<int> containing a sorted list of all newline positions (fill it in BlockMethods.IncorporateLine()).

Knagis avatar Nov 24 '15 10:11 Knagis

Thank you. I am using stream, so I suppose it has to be a change to the parser.

In any case, could you please not remove those properties from Block?

dmitry-shechtman avatar Nov 24 '15 10:11 dmitry-shechtman

For now I don't plan to, that will probably happen on v1. I want remove them because I think it gives people the wrong idea on how to use them. Even for the original purpose - to enable synchronized scrolling between the markdown source and generated HTML code in editors - they are useless if someone wants to use wrapped lines...

Knagis avatar Nov 24 '15 10:11 Knagis

Hey,

May I remove the Question label? This is more of a request.

dmitry-shechtman avatar Dec 16 '15 22:12 dmitry-shechtman

I still think that it is wrong to use these properties in any real life applications - can you describe how you are using them?

Knagis avatar Dec 18 '15 19:12 Knagis

I believe the top post describes a realistic scenario. I saw an old post on CommonMark where jgm said that inline elements should get these as well.

On Fri, Dec 18, 2015 at 9:44 PM, Kārlis Gaņģis [email protected] wrote:

I still think that it is wrong to use these properties in any real life applications - can you describe how you are using them?

— Reply to this email directly or view it on GitHub https://github.com/Knagis/CommonMark.NET/issues/57#issuecomment-165880604 .

dmitry-shechtman avatar Dec 19 '15 08:12 dmitry-shechtman

https://github.com/jgm/cmark/issues/26

CommonMark.NET should live up to jgm's high expectations :laughing:

dmitry-shechtman avatar Dec 24 '15 13:12 dmitry-shechtman