src/Markdig/Renderers/RendererBase.cs
/// <summary>
/// Writes the specified Markdown object.
/// </summary>
/// <param name="obj">The Markdown object to write to this renderer.</param>
Writes the specified Markdown object.
Writes the specified Markdown object .
public void Write(MarkdownObject obj)
        {
            if (obj is null)
            {
                return;
            }
            ObjectWriteBefore?.Invoke(this, obj);
            var objectType = obj.GetType();
            IMarkdownObjectRenderer? renderer;
            if (objectType == previousObjectType)
            {
                renderer = previousRenderer;
            }
            else if (!renderersPerType.TryGetValue(objectType, out renderer))
            {
                for (int i = 0; i < ObjectRenderers.Count; i++)
                {
                    var testRenderer = ObjectRenderers[i];
                    if (testRenderer.Accept(this, obj))
                    {
                        renderersPerType[objectType] = renderer = testRenderer;
                        break;
                    }
                }
            }
            if (renderer != null)
            {
                renderer.Write(this, obj);
                previousObjectType = objectType;
                previousRenderer = renderer;
            }
            else if (obj is ContainerBlock containerBlock)
            {
                WriteChildren(containerBlock);
            }
            else if (obj is ContainerInline containerInline)
            {
                WriteChildren(containerInline);
            }
            ObjectWriteAfter?.Invoke(this, obj);
        }
public void Write ( MarkdownObject obj ) { if ( obj is null ) { return ; } ObjectWriteBefore ? . Invoke ( this , obj ) ; var objectType = obj . GetType ( ) ; IMarkdownObjectRenderer ? renderer ; if ( objectType == previousObjectType ) { renderer = previousRenderer ; } else if ( ! renderersPerType . TryGetValue ( objectType , out renderer ) ) { for ( int i = 0 ; i < ObjectRenderers . Count ; i ++ ) { var testRenderer = ObjectRenderers [ i ] ; if ( testRenderer . Accept ( this , obj ) ) { renderersPerType [ objectType ] = renderer = testRenderer ; break ; } } } if ( renderer != null ) { renderer . Write ( this , obj ) ; previousObjectType = objectType ; previousRenderer = renderer ; } else if ( obj is ContainerBlock containerBlock ) { WriteChildren ( containerBlock ) ; } else if ( obj is ContainerInline containerInline ) { WriteChildren ( containerInline ) ; } ObjectWriteAfter ? . Invoke ( this , obj ) ; }
Writes the specified Markdown object.
Writes the specified Markdown object .
// Calls before writing an object // Handle regular renderers // Calls after writing an object
obj
MarkdownObject
The Markdown object to write to this renderer.
The Markdown object to write to this renderer .