From c9d8b8e3c8c19a08c022b5697be2192da78a97a1 Mon Sep 17 00:00:00 2001 From: Immo Landwerth Date: Tue, 26 Aug 2014 08:15:55 -0700 Subject: [PATCH] Make emitter work with Open XML (fixes #4) --- src/XsdDocumentation/Markup/MamlWriter.cs | 14 ++++ .../Markup/MamlWriterExtensions.cs | 78 +++++++++++-------- 2 files changed, 59 insertions(+), 33 deletions(-) diff --git a/src/XsdDocumentation/Markup/MamlWriter.cs b/src/XsdDocumentation/Markup/MamlWriter.cs index 4c354fc..5ae5c50 100644 --- a/src/XsdDocumentation/Markup/MamlWriter.cs +++ b/src/XsdDocumentation/Markup/MamlWriter.cs @@ -227,6 +227,20 @@ public void EndParagraph() #endregion + #region Bold + + public void StartBold() + { + _xmlWriter.WriteStartElement("legacyBold", Namespaces.Maml); + } + + public void EndBold() + { + _xmlWriter.WriteEndElement(); // legacyBold + } + + #endregion + #region Markup public void StartMarkup() diff --git a/src/XsdDocumentation/Markup/MamlWriterExtensions.cs b/src/XsdDocumentation/Markup/MamlWriterExtensions.cs index a030ded..2fd69a4 100644 --- a/src/XsdDocumentation/Markup/MamlWriterExtensions.cs +++ b/src/XsdDocumentation/Markup/MamlWriterExtensions.cs @@ -12,6 +12,13 @@ internal static class MamlWriterExtensions private const string NonBlockingSpaceEntityName = " "; private const string XmlTopicType = "3272D745-2FFC-48C4-9E9D-CF2B2B784D5F"; + public static void WriteNonBlockingSpace(this MamlWriter writer) + { + writer.StartMarkup(); + writer.WriteRaw(NonBlockingSpaceEntityName); + writer.EndMarkup(); + } + public static void WriteHtmlIndent(this MamlWriter writer, int level) { writer.StartMarkup(); @@ -39,7 +46,19 @@ public static void WriteHtmlTopicLink(this MamlWriter writer, Topic topic) public static void StartHtmlArtItem(this MamlWriter writer, ArtItem artItem) { writer.StartMarkup(); - writer.WriteStartElement("nobr", String.Empty); + + // Emitting a tag breaks the Open XML output. I'm pretty + // sure that I've added this originally in order to avoid weird + // breaks between the icon and whatever comes after (usually a + // link or text). However, after visual inspection, I can't find + // any cases where this can actually occur. + // + // If we need to add this back, we should probably either special + // case the output type and suppress for Open XML or find a + // MAML way of doing it (which doesn't exist today). + // + // writer.WriteStartElement("nobr", String.Empty); + writer.WriteStartElement("artLink"); writer.WriteAttributeString("target", artItem.Id); writer.WriteEndElement(); @@ -48,7 +67,10 @@ public static void StartHtmlArtItem(this MamlWriter writer, ArtItem artItem) public static void EndHtmlArtItem(this MamlWriter writer) { - writer.WriteEndElement(); // nobr + // See comments about in StartHtmlArtItem(). + // + // writer.WriteEndElement(); // nobr + writer.EndMarkup(); } @@ -66,24 +88,6 @@ public static void WriteHtmlArtItemWithTopicLink(this MamlWriter writer, ArtItem writer.EndHtmlArtItem(); } - private static void WriteHtmlNamespaceLink(this MamlWriter writer, Context context, string namespaceUri) - { - var topic = context.TopicManager.GetNamespaceTopic(namespaceUri); - if (topic == null) - writer.WriteString(namespaceUri ?? "Empty"); - else - writer.WriteHtmlTopicLink(topic); - } - - private static void WriteHtmlSchemaLink(this MamlWriter writer, Context context, XmlSchemaObject obj) - { - var topic = context.TopicManager.GetTopic(obj.GetSchema()); - if (topic == null) - writer.WriteString(obj.GetSchemaName()); - else - writer.WriteHtmlTopicLink(topic); - } - public static void WriteArtItemInline(this MamlWriter writer, ArtItem artItem) { writer.WriteMediaLinkInline(artItem.Id); @@ -99,6 +103,15 @@ private static void WriteTopicLinkWithReferenceMarker(this MamlWriter writer, To writer.WriteLink(rootItemTopic.Id, rootItemTopic.LinkTitle, XmlTopicType); } + public static void WriteSchemaLink(this MamlWriter writer, Context context, XmlSchemaObject obj) + { + var topic = context.TopicManager.GetTopic(obj.GetSchema()); + if (topic == null) + writer.WriteString("Empty"); + else + writer.WriteTopicLink(topic); + } + public static void WriteNamespaceLink(this MamlWriter writer, Context context, string namespaceUri) { var topic = context.TopicManager.GetNamespaceTopic(namespaceUri); @@ -123,11 +136,11 @@ public static void WriteSummaryForObject(this MamlWriter writer, Context context public static void WriteNamespaceInfo(this MamlWriter writer, Context context, string namespaceUri) { writer.StartParagraph(); - writer.StartMarkup(); - writer.WriteRaw("Namespace: "); - writer.WriteHtmlNamespaceLink(context, namespaceUri); - writer.WriteRaw("
"); - writer.EndMarkup(); + writer.StartBold(); + writer.WriteString("Namespace:"); + writer.EndBold(); + writer.WriteNonBlockingSpace(); + writer.WriteNamespaceLink(context, namespaceUri); writer.EndParagraph(); } @@ -135,15 +148,14 @@ public static void WriteNamespaceAndSchemaInfo(this MamlWriter writer, Context c { var targetNamespace = obj.GetSchema().TargetNamespace; + writer.WriteNamespaceInfo(context, targetNamespace); + writer.StartParagraph(); - writer.StartMarkup(); - writer.WriteRaw("Namespace: "); - writer.WriteHtmlNamespaceLink(context, targetNamespace); - writer.WriteRaw("
"); - writer.WriteRaw("Schema: "); - writer.WriteHtmlSchemaLink(context, obj); - writer.WriteRaw("
"); - writer.EndMarkup(); + writer.StartBold(); + writer.WriteString("Schema:"); + writer.EndBold(); + writer.WriteNonBlockingSpace(); + writer.WriteSchemaLink(context, obj); writer.EndParagraph(); }