/// <summary> /// Causes the <see cref="ITagDefinition"/> to remove any whitespace it sees fit that is around its /// identified <see cref="ITagInstance"/>s. An <see cref="ITagDefinition"/> does not need to remove /// any whitespace, if it doesn't want to. /// </summary> /// <remarks> /// This method is always called before <see cref="ITagDefinition.Render"/> is called on any <see cref="ITagDefinition"/>. /// The order in which this method is called across the different <see cref="ITagDefinition"/>s is undefined. /// </remarks> /// <param name="context"> /// The <see cref="IWhitespaceRemovalContext"/> contains all <see cref="ITagInstance"/>s, the input text, /// and methods that allow for the removal of whitespace. /// </param> public void RemoveWhitespace(IWhitespaceRemovalContext context) { IEnumerable <IOpenTagInstance> tagInstances = context.Tags.Where(t => t.ParentDefinition == this) .OfType <OpenTagInstance>(); foreach (IOpenTagInstance openTag in tagInstances) { ICloseTagInstance closeTag = openTag.CloseTag; IList <ListItemTagInstance> listItemTags = context.GetTagsAfter(openTag) .TakeWhile(t => t != closeTag) .WhereStackDepthIs(0) .OfType <ListItemTagInstance>() .ToList(); //Don't remove whitespace if there's only whitespace in between the open and close tags //because the tag won't be rendered if (listItemTags.Any() == false && _WhitespaceRegex.Match(context.GetRenderString(openTag, closeTag)).Success) { continue; } context.RemoveWhitespaceBeforeTag(openTag, 1); context.RemoveWhitespaceAfterTag(openTag, 1); context.RemoveWhitespaceBeforeTag(openTag.CloseTag, 1); context.RemoveWhitespaceAfterTag(openTag.CloseTag, 2); } }
/// <summary> /// Causes the <see cref="ITagDefinition"/> to remove any whitespace it sees fit that is around its /// identified <see cref="ITagInstance"/>s. An <see cref="ITagDefinition"/> does not need to remove any /// whitespace, if it doesn't want to. /// </summary> /// <remarks> /// This method is always called before <see cref="ITagDefinition.Render"/> is called on any /// <see cref="ITagDefinition"/>. The order in which this method is called across the different /// <see cref="ITagDefinition"/>s is undefined. /// </remarks> /// <param name="context"> /// The <see cref="IWhitespaceRemovalContext"/> contains all <see cref="ITagInstance"/>s, the input text, /// and methods that allow for the removal of whitespace. /// </param> public override void RemoveWhitespace(IWhitespaceRemovalContext context) { IEnumerable <IOpenTagInstance> tagInstances = context.Tags.Where(t => t.ParentDefinition == this) .OfType <IOpenTagInstance>(); foreach (IOpenTagInstance openTag in tagInstances) { context.RemoveWhitespaceBeforeTag(openTag, 1); context.RemoveWhitespaceAfterTag(openTag, 1); context.RemoveWhitespaceBeforeTag(openTag.CloseTag, 1); context.RemoveWhitespaceAfterTag(openTag.CloseTag, 2); } }
/// <summary> /// Causes the <see cref="ITagDefinition"/> to remove any whitespace it sees fit that is around its /// identified <see cref="ITagInstance"/>s. An <see cref="ITagDefinition"/> does not need to remove any /// whitespace, if it doesn't want to. /// </summary> /// <remarks> /// <para> /// This method is always called before <see cref="ITagDefinition.Render"/> is called on any /// <see cref="ITagDefinition"/>. The order in which this method is called across the different /// <see cref="ITagDefinition"/>s is undefined. /// </para> /// <para> /// This method does nothing in its default implementation. Inheritors should override this method /// if they want to perform whitespace removal. /// </para> /// </remarks> /// <param name="context"> /// The <see cref="IWhitespaceRemovalContext"/> contains all <see cref="ITagInstance"/>s, the input text, /// and methods that allow for the removal of whitespace. /// </param> public virtual void RemoveWhitespace(IWhitespaceRemovalContext context) { //Do nothing by default. Override if you need to perform something here. }