markdown-js icon indicating copy to clipboard operation
markdown-js copied to clipboard

Add start and end information to JsonML tree

Open Janpot opened this issue 10 years ago • 3 comments

Would it be possible to add start and end position of the original source to the JsonML tree and the generated HTML as classes or data attributes?

I would use this to make a markdown editor work together with a preview window to keep the scroll position in sync

Janpot avatar Aug 21 '13 19:08 Janpot

This is a nice idea.

I think including the line numbers in the markdown JsonML tree is a no-brainer, but I would strip them out during the conversion to an HTML JsonML tree, and certainly before rendering to HTML as they would be rarely used.

Do you need both the start and end position for every element, or would it be sufficient to have just the start line for every block element in the tree? That information is already available to us internally so would be a lot simpler to implement.

evilstreak avatar Aug 22 '13 17:08 evilstreak

Thanks for your reply,

The reason I want them in the Html as well is to be able to quickly query the resulting DOM to scroll the corresponding element into view. Perhaps it is also possible by adding this manually in an intermediate step. I will have to test the API more to find out. Any tips on this are always welcome. You could also add this as an option to the html generation if you think this could be useful. I understand in most applications people don't want this in the resulting Html.

The reason for having the end position is to be able to interpolate the current position in the block to find the cursor position in the resulting DOM (and scroll accordingly). This would especially be necessary for very large paragraphs. Perhaps I can do this by sorting the tree by start position and adding the start position of the next element as the end position of the current element. But this could potentially become resource consuming. Anyway, my first prototype would probably not include this interpolation.

So yes, to begin with I think having just the start position would be sufficient.

Janpot avatar Aug 22 '13 19:08 Janpot

Hi, I would be also interested in this feature as I'm also trying to find a way to jump into correct line of original markdown source basing on generated DOM node. Any chance to have it implemented soon?

mbuczko avatar Jan 11 '14 23:01 mbuczko