private static bool WriteFlowDocument(XmlTextReader xamlReader, XmlTextWriter htmlWriter)
        {
            if (!HtmlFromXamlConverter.ReadNextToken(xamlReader))
            {
                return(false);
            }
            if (xamlReader.NodeType != XmlNodeType.Element || xamlReader.Name != "FlowDocument")
            {
                return(false);
            }
            StringBuilder inlineStyle = new StringBuilder();

            htmlWriter.WriteStartElement("HTML");
            htmlWriter.WriteStartElement("BODY");
            HtmlFromXamlConverter.WriteFormattingProperties(xamlReader, htmlWriter, inlineStyle, "BODY");
            HtmlFromXamlConverter.WriteElementContent(xamlReader, htmlWriter, inlineStyle, new List <string>(), new List <string>());
            htmlWriter.WriteEndElement();
            htmlWriter.WriteEndElement();
            return(true);
        }
        private static void WriteElementContent(XmlTextReader xamlReader, XmlTextWriter htmlWriter, StringBuilder inlineStyle, List <string> xamlAncestors, List <string> htmlAncestors)
        {
            bool flag = false;

            if (xamlReader.IsEmptyElement)
            {
                if (htmlWriter != null && !flag && inlineStyle.Length > 0)
                {
                    htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
                    inlineStyle.Remove(0, inlineStyle.Length);
                }
                return;
            }
            while (HtmlFromXamlConverter.ReadNextToken(xamlReader) && xamlReader.NodeType != XmlNodeType.EndElement)
            {
                XmlNodeType nodeType = xamlReader.NodeType;
                switch (nodeType)
                {
                case XmlNodeType.Element:
                    if (xamlReader.Name.Contains(".") && xamlReader.Name != "Table.Columns")
                    {
                        HtmlFromXamlConverter.AddComplexProperty(xamlReader, inlineStyle, xamlAncestors, htmlAncestors);
                        continue;
                    }
                    if (htmlWriter != null && !flag && inlineStyle.Length > 0)
                    {
                        htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
                        inlineStyle.Remove(0, inlineStyle.Length);
                    }
                    flag = true;
                    HtmlFromXamlConverter.WriteElement(xamlReader, htmlWriter, inlineStyle, xamlAncestors, htmlAncestors);
                    continue;

                case XmlNodeType.Attribute:
                case XmlNodeType.Entity:
                case XmlNodeType.ProcessingInstruction:
                    continue;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    break;

                case XmlNodeType.EntityReference:
                    if (htmlWriter != null)
                    {
                        htmlWriter.WriteRaw("&nbsp;");
                    }
                    flag = true;
                    continue;

                case XmlNodeType.Comment:
                    if (htmlWriter != null)
                    {
                        if (!flag && inlineStyle.Length > 0)
                        {
                            htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
                        }
                        htmlWriter.WriteComment(xamlReader.Value);
                    }
                    flag = true;
                    continue;

                default:
                    if (nodeType != XmlNodeType.SignificantWhitespace)
                    {
                        continue;
                    }
                    break;
                }
                if (htmlWriter != null)
                {
                    if (!flag && inlineStyle.Length > 0)
                    {
                        htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
                    }
                    if (xamlReader.NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        for (int i = 0; i < xamlReader.Value.Length; i++)
                        {
                            if (xamlReader.Value[i] == ' ')
                            {
                                htmlWriter.WriteRaw("&nbsp;");
                            }
                            else
                            {
                                htmlWriter.WriteString(xamlReader.Value[i].ToString());
                            }
                        }
                    }
                    else
                    {
                        htmlWriter.WriteString(xamlReader.Value);
                    }
                }
                flag = true;
            }
        }