public void ProcessOutput(MarkupWriter writer) { var tagDefinition = writer.GetTagDefinition(TagName); // If the tag is not defined, silently ignore it if (tagDefinition == null) { return; } if (IsOpeningTag) { // If we force a nesting, record the injection set so that we can collapse it later var injection = EnsureCorrectNesting(writer, tagDefinition); if (injection.Length > 0) { writer.Injections.Push(injection); } var allowedAttributes = (from a in Attributes where tagDefinition.AllowedAttributes.Contains(a.Key, StringComparer.InvariantCultureIgnoreCase) select a).ToDictionary(k => k.Key, v => v.Value); // We use the tag name from the definition here so that any upscaling can occur if (tagDefinition.IsShortcut) { writer.ShortcutTag(tagDefinition, allowedAttributes); } else { writer.OpenTag(tagDefinition, allowedAttributes); } } else { // Only continue if the tag is actually in the stack, else ignore it silently if (writer.OpenTags.Contains(tagDefinition.TagName, StringComparer.InvariantCultureIgnoreCase)) { // Close any tags above this one in the stack while (writer.OpenTags.Count > 0 && !writer.OpenTags.Peek().Equals(tagDefinition.TagName, StringComparison.InvariantCultureIgnoreCase)) { writer.CloseTag(); } // If there are still open tags, we must be next in line if (writer.OpenTags.Count > 0) { writer.CloseTag(); } } } }
private static void InjectParent(MarkupWriter writer, List <string> injection, TagDefinition injectionTag) { injection.Add(injectionTag.TagName); injection.AddRange(EnsureCorrectNesting(writer, injectionTag)); writer.OpenTag(injectionTag, null); }