Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Find document modified region #4

#1

GitHub Issue 114

I’m trying to implement md syntax color in Eclipse, and I need to identify a damaged region, meaning the smallest possible region that was affected by user modification
The idea is to parse only this region, and then to color only its text according to the result of the parsing
I’ve tried to use first double enter before user modification start, and first double enter after user modification end, it works great (very fast) but not for code regions, for fenced code block for example, the double enter can be inside the block, but the parser has only this region and doesn’t know about it
Also for fenced code block, if put by the user, it can transform everything until the end of the document in fenced code block
So the question is how to find where to start and end the (smallest possible) region which contains the modification part in a way that after parsing that, it would be such as the whole document was parsed (the unmodified beginning and end parts of the document would look the same)

  • replies 1
  • views 3.3K
  • likes 0
#2

@iuscl-ide, markdown uses indentation and prefixes based on context so the safest bet is to walk the AST up until you get the document level element and use its text range. Walk AST up until node.getParent().getParent() == null or node.getParent() instanceof Document then use this node as the minimal element to re-parse.

That way if you modify an item nested into several indenting or prefixed elements you will still have the text properly parsed.

You can also implement a more intelligent algorithm but it will be a PITA to debug. Lots of combinations that will need to be tested.