/// <summary> /// Combines the sequence of spans to a single span and adds a separator between them. /// </summary> /// <param name="spans">The sequence of spans to combine</param> /// <param name="separator">The separator to insert between spans.</param> /// <returns> /// Returns a new span containing all the specified spans: /// <list type="bullet"> /// <item> /// <description>If <paramref name="spans"/> is empty, an instance of <see cref="MdEmptySpan"/> will be returned</description> /// </item> /// <item> /// <description>If <paramref name="spans"/> contains a single item, this single span will be returned</description> /// </item> /// <item> /// <description> /// Otherwise a instance of <see cref="MdCompositeSpan"/> is returned that wraps all the specified spans. /// Between two elements of the input sequence, the specified separator is inserted /// </description> /// </item> /// </list> /// </returns> public static MdSpan Join(this IEnumerable <MdSpan> spans, MdSpan?separator) { // no spans to join => return empty span if (!spans.Any()) { return(MdEmptySpan.Instance); } // a single span to join => just return the single span else if (!spans.Skip(1).Any()) { return(spans.Single()); } // multiple span but no separator => create composite span with all the specified spans else if (separator == null) { return(new MdCompositeSpan(spans)); } // multiple spans and separator specified // => create composite span and add separator between individual spans else { var composite = new MdCompositeSpan(); foreach (var span in spans) { if (composite.Spans.Count > 0) { composite.Add(separator.DeepCopy()); } composite.Add(span); } return(composite); } }
public void Visit(MdCompositeSpan compositeSpan) { PushNewNode(compositeSpan); foreach (var span in compositeSpan) { span.Accept(this); } PopNode(); }
/// <summary> /// Creates a new instance of <see cref="MdEmphasisSpan"/> with the specified content /// </summary> /// <param name="text">The text to emphasize.</param> public static MdEmphasisSpan Emphasis(MdCompositeSpan text) => new MdEmphasisSpan(text);
/// <summary> /// Creates a new instance of <see cref="MdStrongEmphasisSpan"/> with the specified content. /// </summary> /// <param name="text">The text to emphasize</param> /// <remarks><c>Bold()</c> is an alias for <c>StrongEmphasis()</c></remarks> public static MdStrongEmphasisSpan Bold(MdCompositeSpan text) => StrongEmphasis(text);
/// <summary> /// Creates a new instance of <see cref="MdStrongEmphasisSpan"/> with the specified content. /// </summary> /// <param name="text">The text to emphasize</param> public static MdStrongEmphasisSpan StrongEmphasis(MdCompositeSpan text) => new MdStrongEmphasisSpan(text);
/// <summary> /// Creates a new instance of <see cref="MdEmphasisSpan"/> with the specified content /// </summary> /// <param name="text">The text to emphasize.</param> /// <remarks><c>Italic()</c> is an alias for <c>Emphasis()</c></remarks> public static MdEmphasisSpan Italic(MdCompositeSpan text) => Emphasis(text);
/// <summary> /// Initializes a new instance of <see cref="MdTableRow"/> with the specified cell. /// </summary> /// <param name="cell">The row's cell</param> public MdTableRow(MdCompositeSpan cell) : this((MdSpan)cell) { }
/// <summary> /// Initializes a new instance of <see cref="MdEmphasisSpan"/> with the specified content. /// </summary> /// <param name="text">The text to emphasize.</param> public MdEmphasisSpan(MdCompositeSpan text) : this((MdSpan)text) { }
/// <summary> /// Creates a new instance of <see cref="MdTableRow"/> with the specified cell. /// </summary> /// <param name="cell">The row's cells</param> public static MdTableRow Row(MdCompositeSpan cell) => new MdTableRow(cell);