/// <summary> /// Writes the specified Markdown object. /// </summary> /// <param name="obj">The Markdown object to write to this renderer.</param> public void Write(MarkdownObject obj) { if (obj == null) { return; } // Calls before writing an object ObjectWriteBefore?.Invoke(this, obj); var objectType = obj.GetType(); IMarkdownObjectRenderer renderer; // Handle regular renderers 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); } // Calls after writing an object ObjectWriteAfter?.Invoke(this, obj); }
/// <summary> /// Writes the specified Markdown object. /// </summary> /// <typeparam name="T">A MarkdownObject type</typeparam> /// <param name="obj">The Markdown object to write to this renderer.</param> public void Write <T>(T obj) where T : Atom { if (obj == null) { return; } var objectType = obj.GetType(); // Calls before writing an object ObjectWriteBefore?.Invoke(this, obj); // Handle regular renderers IWpfMathAtomRenderer renderer = previousObjectType == objectType ? previousRenderer : null; if (renderer == null && !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; } } } var writeResult = WriteResult.Completed; if (renderer != null) { writeResult = renderer.Write(this, obj); } else { // Some default could be here, but we don't have // a container class deriving from Atom like the container classes in Markdig } previousObjectType = objectType; previousRenderer = renderer; // Calls after writing an object if (writeResult == WriteResult.Completed) // if the object was completed here { OnCompletionOfElement(obj); // then announce completion (otherwise completion is usually announced in some callback code of the specific renderer) } }