src/Blocks/CodeBlock.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)
        {
            bool noFence = formatting?.UseIndentsForCodeBlocks == true && string.IsNullOrEmpty(Language);
            string indent = Indent;
            if (noFence)
                indent += new string(' ', 4);
            var sw = new StringWriter();
            base.Write(sw, formatting);
            string codeText = sw.ToString().TrimEnd('\r', '\n').Replace("\n", "\n" + indent);
            bool needsEscape = codeText.Contains(FencedCodeBlockMarker);
            writer.Write(indent);
            if (noFence)
            {
                writer.Write(codeText);
            }
            else
            {
                if (needsEscape) writer.Write(FencedCodeBlockMarker[0]); 
                writer.Write(FencedCodeBlockMarker);
                writer.WriteLine(Language);
                writer.WriteLine(codeText);
                writer.Write(indent);
                if (needsEscape) writer.Write(FencedCodeBlockMarker[0]);
                writer.WriteLine(FencedCodeBlockMarker);
            }
            writer.WriteLine();
        }
public override void Write ( TextWriter writer , MarkdownFormatting formatting ) { bool noFence = formatting ? . UseIndentsForCodeBlocks == true && string . IsNullOrEmpty ( Language ) ; string indent = Indent ; if ( noFence ) indent += new string ( ' ' , 4 ) ; var sw = new StringWriter ( ) ; base . Write ( sw , formatting ) ; string codeText = sw . ToString ( ) . TrimEnd ( ' \r ' , ' \n ' ) . Replace ( " \n " , " \n " + indent ) ; bool needsEscape = codeText . Contains ( FencedCodeBlockMarker ) ; writer . Write ( indent ) ; if ( noFence ) { writer . Write ( codeText ) ; } else { if ( needsEscape ) writer . Write ( FencedCodeBlockMarker [ 0 ] ) ; writer . Write ( FencedCodeBlockMarker ) ; writer . WriteLine ( Language ) ; writer . WriteLine ( codeText ) ; writer . Write ( indent ) ; if ( needsEscape ) writer . Write ( FencedCodeBlockMarker [ 0 ] ) ; writer . WriteLine ( FencedCodeBlockMarker ) ; } writer . WriteLine ( ) ; }
Writes the block to the given TextWriter.
Writes the block to the given TextWriter .
// add one more to escape the entire block.
writer
TextWriter
None
formatting
MarkdownFormatting
None