Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Make emitter work with Open XML (fixes #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrajobst committed Aug 27, 2014
1 parent 1d749bf commit c9d8b8e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 33 deletions.
14 changes: 14 additions & 0 deletions src/XsdDocumentation/Markup/MamlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
78 changes: 45 additions & 33 deletions src/XsdDocumentation/Markup/MamlWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 <nobr> 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 <nobr> 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();
Expand All @@ -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 <nobr> in StartHtmlArtItem().
//
// writer.WriteEndElement(); // nobr

writer.EndMarkup();
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -123,27 +136,26 @@ 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("<b>Namespace:</b> ");
writer.WriteHtmlNamespaceLink(context, namespaceUri);
writer.WriteRaw("<br/>");
writer.EndMarkup();
writer.StartBold();
writer.WriteString("Namespace:");
writer.EndBold();
writer.WriteNonBlockingSpace();
writer.WriteNamespaceLink(context, namespaceUri);
writer.EndParagraph();
}

public static void WriteNamespaceAndSchemaInfo(this MamlWriter writer, Context context, XmlSchemaObject obj)
{
var targetNamespace = obj.GetSchema().TargetNamespace;

writer.WriteNamespaceInfo(context, targetNamespace);

writer.StartParagraph();
writer.StartMarkup();
writer.WriteRaw("<b>Namespace:</b> ");
writer.WriteHtmlNamespaceLink(context, targetNamespace);
writer.WriteRaw("<br/>");
writer.WriteRaw("<b>Schema:</b> ");
writer.WriteHtmlSchemaLink(context, obj);
writer.WriteRaw("<br/>");
writer.EndMarkup();
writer.StartBold();
writer.WriteString("Schema:");
writer.EndBold();
writer.WriteNonBlockingSpace();
writer.WriteSchemaLink(context, obj);
writer.EndParagraph();
}

Expand Down

0 comments on commit c9d8b8e

Please sign in to comment.