public LinkMatch(NestableItem item, string wikiLink, bool isExternal, string linkEnding) { this.Index = item.Index; this.Length = item.Length; this.Value = item.Value; this.WikiLink = wikiLink; this.LinkEnding = linkEnding; this.HasChildren = item.Children.Count > 0; if (linkEnding != null) { this.Length += linkEnding.Length; } this.Uri = null; this.IsExternal = isExternal; }
/// <summary> /// Attempts to parse potentially nested items from the text at the specified position. /// </summary> /// <param name="wikiText">The input text.</param> /// <param name="itemPos">Pass as the position of the opening marker. Returns as the position just after the closing marker.</param> /// <param name="openMarker">The opening marker (eg. "{{" or "[[").</param> /// <param name="closeMarker">The closing marker (eg. "}}" or "]]").</param> /// <returns>The item if one could be parsed, <c>null</c> otherwise.</returns> private static NestableItem ParseNestedItem(string wikiText, string openMarker, string closeMarker, ref int itemPos) { var item = new NestableItem(wikiText, itemPos, 0); int p; int pOpening; int pClosing; p = itemPos + openMarker.Length; while (true) { // $todo(jeff.lill): This is not very efficient. pOpening = wikiText.IndexOf(openMarker, p); pClosing = wikiText.IndexOf(closeMarker, p); if (pClosing == -1) { // Unbalanced {{ .. }} itemPos = p; return(null); } else if (pClosing < pOpening || pOpening == -1) { break; } NestableItem child;; child = ParseNestedItem(wikiText, openMarker, closeMarker, ref pOpening); if (child == null) { break; } item.Children.Add(child); p = child.Index + child.Length; } itemPos = pClosing + closeMarker.Length; item.Length = itemPos - item.Index; item.Value = wikiText.Substring(item.Index, item.Length); return(item); }