Exemplo n.º 1
0
        private IEnumerable <CreoleRichTextElementNodeData> _GetRootNodesFrom(TokenRange <CreoleTokenCode> tokens, IEnumerable <CreoleRichTextElementData> elementsData)
        {
            var rootNodes           = new List <CreoleRichTextElementNodeData>();
            var visitedElementTypes = new List <CreoleRichTextElementType>(10);

            foreach (var elementData in elementsData)
            {
                var node = new CreoleRichTextElementNodeData(elementData);

                IList <CreoleRichTextElementNodeData> siblingNodes = rootNodes;
                while (siblingNodes.Count > 0 && _Contains(siblingNodes[siblingNodes.Count - 1], node))
                {
                    var parentNode = siblingNodes[siblingNodes.Count - 1];
                    siblingNodes = parentNode.ChildNodes;
                    visitedElementTypes.Add(parentNode.ElementType);
                }

                if (node.ElementType == CreoleRichTextElementType.Hyperlink)
                {
                    var contentRange = tokens.SubRange(node.ContentStartIndex, (node.ContentEndIndex - node.ContentStartIndex));
                    foreach (var hyperlinkContentElementNodeData in _GetHyperlinkContentElementNodesData(contentRange, visitedElementTypes))
                    {
                        node.ChildNodes.Add(_AddIndexOffset(node.ContentStartIndex, hyperlinkContentElementNodeData));
                    }
                }

                siblingNodes.Add(node);
                visitedElementTypes.Clear();
            }

            return(rootNodes);
        }
Exemplo n.º 2
0
        private string _GetContentFrom(TokenRange <CreoleTokenCode> tokens, CreoleRichTextElementNodeData richTextElementData)
        {
            var contentStartIndex = richTextElementData.ContentStartIndex;
            var contentEndIdnex   = richTextElementData.ContentEndIndex;
            var contentRange      = tokens.SubRange(contentStartIndex, (contentEndIdnex - contentStartIndex));

            return(TokenRangeHelper.GetPlainText(contentRange));
        }
Exemplo n.º 3
0
        private string _GetUrlFrom(TokenRange <CreoleTokenCode> tokens, CreoleRichTextElementNodeData richTextElementData)
        {
            var urlStartIndex = richTextElementData.UrlStartIndex;
            var urlEndIdnex   = richTextElementData.UrlEndIndex;
            var urlRange      = tokens.SubRange(urlStartIndex, (urlEndIdnex - urlStartIndex));

            return(TokenRangeHelper.GetPlainText(urlRange));
        }
Exemplo n.º 4
0
 protected TokenRange <CreoleTokenCode> GetTokens(int startIndex, int endIndex)
 {
     if (startIndex < _elementStartIndex)
     {
         throw new ArgumentException("Content cannot begin before the element starts.", nameof(startIndex));
     }
     if (endIndex > _elementEndIndex)
     {
         throw new ArgumentException("Content cannot end after the element ends.", nameof(startIndex));
     }
     return(_tokens.SubRange(startIndex, (endIndex - startIndex)));
 }
Exemplo n.º 5
0
        private IEnumerable <Element> _GetCreoleElements(TokenRange <CreoleTokenCode> tokens, int startIndex, int endIndex, IEnumerable <CreoleRichTextElementNodeData> nodesData)
        {
            var elements           = new List <Element>();
            var subRangeStartIndex = startIndex;

            foreach (var nodeData in nodesData)
            {
                if (subRangeStartIndex < nodeData.StartIndex)
                {
                    elements.Add(new TextElement(TokenRangeHelper.GetPlainText(tokens.SubRange(subRangeStartIndex, (nodeData.StartIndex - subRangeStartIndex)))));
                }

                elements.Add(_GetCreoleElementFrom(tokens, nodeData));
                subRangeStartIndex = nodeData.EndIndex;
            }
            if (subRangeStartIndex < endIndex)
            {
                var subRange = tokens.SubRange(subRangeStartIndex, (endIndex - subRangeStartIndex));
                elements.Add(new TextElement(TokenRangeHelper.GetPlainText(subRange)));
            }

            return(elements);
        }
 private CreoleRichTextElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens, ICreoleRichTextElementDataIterator elementIterator)
 {
     _tokens  = tokens;
     Context  = context;
     _element = elementIterator;
     if (_element != null && _element.MoveNext())
     {
         _token      = _tokens.SubRange(_startIndex, (_element.Current.StartIndex - _startIndex)).GetEnumerator();
         _startIndex = _element.Current.EndIndex;
     }
     else
     {
         _element?.Dispose();
         _element    = null;
         _token      = _tokens.GetEnumerator();
         _startIndex = _tokens.Count;
     }
 }