src/Lists/MarkdownList.cs
/// <summary>
/// Writes the block to the given TextWriter.
/// </summary>
/// <param name="writer">writer</param>
/// <param name="formatting">optional formatting</param>
Writes the block to the given TextWriter.
Writes the block to the given TextWriter .
public override void Write(TextWriter writer, MarkdownFormatting formatting)
        {
            if (!AllBlocks().Any()) return;
            string indent = Indent;
            var sb = new StringBuilder();
            for (int i = 0; i < Children.Count; i++)
            {
                var block = Children[i];
                string prefix = GetPrefix(formatting, i);
                for (var index = 0; index < block.Count; index++)
                {
                    var item = block[index];
                    if (index > 0 && item is not MarkdownList)
                        sb.AppendLine();
                    sb.Append(indent + prefix); 
                    if (index == 0)
                        prefix = new string(' ', prefix.Length);
                    var sw = new StringWriter();
                    item.Write(sw, formatting);
                    sb.Append(sw.ToString()
                        .TrimEnd('\r', '\n')
                        .Replace("\n", "\n" + indent + prefix));
                    if (item is not MarkdownList || index < block.Count-1)
                        sb.AppendLine();
                }
                if (block.Count > 1)
                    sb.AppendLine();
            }
            writer.Write(sb.ToString().TrimEnd('\r', '\n') + Environment.NewLine + Environment.NewLine);
        }
public override void Write ( TextWriter writer , MarkdownFormatting formatting ) { if ( ! AllBlocks ( ) . Any ( ) ) return ; string indent = Indent ; var sb = new StringBuilder ( ) ; for ( int i = 0 ; i < Children . Count ; i ++ ) { var block = Children [ i ] ; string prefix = GetPrefix ( formatting , i ) ; for ( var index = 0 ; index < block . Count ; index ++ ) { var item = block [ index ] ; if ( index > 0 && item is not MarkdownList ) sb . AppendLine ( ) ; sb . Append ( indent + prefix ) ; if ( index == 0 ) prefix = new string ( ' ' , prefix . Length ) ; var sw = new StringWriter ( ) ; item . Write ( sw , formatting ) ; sb . Append ( sw . ToString ( ) . TrimEnd ( ' \r ' , ' \n ' ) . Replace ( " \n " , " \n " + indent + prefix ) ) ; if ( item is not MarkdownList || index < block . Count - 1 ) sb . AppendLine ( ) ; } if ( block . Count > 1 ) sb . AppendLine ( ) ; } writer . Write ( sb . ToString ( ) . TrimEnd ( ' \r ' , ' \n ' ) + Environment . NewLine + Environment . NewLine ) ; }
Writes the block to the given TextWriter.
Writes the block to the given TextWriter .
// # or - // Prepare for any sub-elements. We must indent up to the text.
writer
TextWriter
None
formatting
MarkdownFormatting
None