Ejemplo n.º 1
0
 /// <summary>
 /// Render the node as a string
 /// </summary>
 public override string ToString()
 {
     using (var writer = new StringWriter())
     {
         var visitor = new HtmlVisitor(writer);
         Visit(visitor);
         visitor.Flush();
         return(writer.ToString());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert a Rich Text Format (RTF) document to HTML
        /// </summary>
        /// <param name="source">The source RTF document (either a <see cref="string"/>, <see cref="TextReader"/>, or <see cref="Stream"/>)</param>
        /// <param name="writer"><see cref="XmlWriter"/> that the HTML will be written to</param>
        /// <param name="settings">The settings used in the HTML rendering</param>
        /// <example>
        /// This overload can be used for creating a document that can be further manipulated
        /// <code lang="csharp"><![CDATA[var doc = new XDocument();
        /// using (var writer = doc.CreateWriter())
        /// {
        ///   Rtf.ToHtml(rtf, writer);
        /// }]]>
        /// </code>
        /// </example>
        public static void ToHtml(RtfSource source, XmlWriter writer, RtfHtmlSettings settings = null)
        {
            var parser = new Parser(source.Reader);
            var doc    = parser.Parse();

            if (doc.HasHtml)
            {
                new Model.RawBuilder().Build(doc, writer);
            }
            else
            {
                var html    = new Model.Builder().Build(parser.Parse());
                var visitor = new Model.HtmlVisitor(writer)
                {
                    Settings = settings ?? new RtfHtmlSettings()
                };
                visitor.Visit(html);
            }
            writer.Flush();
        }