From cbad3e9f03dfe8f99001f7d379bdd7deffe3b7fa Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Mon, 25 Mar 2019 18:34:50 +0100 Subject: [PATCH] Docs: Added some inline code. --- src/conversion/upcastdispatcher.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/conversion/upcastdispatcher.js b/src/conversion/upcastdispatcher.js index 4f1bea370..9cef8e821 100644 --- a/src/conversion/upcastdispatcher.js +++ b/src/conversion/upcastdispatcher.js @@ -283,6 +283,19 @@ export default class UpcastDispatcher { // Split element to allowed parent. const splitResult = this.conversionApi.writer.split( modelCursor, allowedParent ); + // Using the range returned by `model.Writer#split`, pair original elements with their split parts. + // The range returned from the writer spans "between" the split or precisely saying, from the end of the split element + // to the beginning of the other part of the split element: + // + // X[]Y -> + // X[]Y + // + // After the split no meaningful content can be between the positions in `splitRange` - they have to be touching. + // Also, because of how splitting works, it is easy to notice, that "closing tags" are in the reverse order than "opening tags". + // Also, since we split all those elements, each of them has to have the other part. + // + // With those observations in mind, we will pair the original elements with their split parts by saving "closing tags" and matching + // them with "opening tags" in the reverse order. For that we can use a stack. const stack = []; for ( const treeWalkerValue of splitResult.range.getWalker() ) {