public static void ToHtml(RtfSource source, XmlWriter writer, RtfHtmlSettings settings = null) { var parser = new Parser(source.Reader); var interpreter = new Interpreter(writer); interpreter.ToHtml(parser.Parse(), settings); }
/// <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="TextWriter"/> that the HTML will be written to</param> /// <param name="settings">The settings used in the HTML rendering</param> public static void ToHtml(RtfSource source, TextWriter writer, RtfHtmlSettings settings = null) { using (var xmlWriter = new HtmlTextWriter(writer, settings)) { ToHtml(source, xmlWriter, settings); } }
public void ToHtml(Document doc, RtfHtmlSettings settings) { _footnotes.Clear(); _footnoteIdx = 0; _html = doc.HasHtml ? (IHtmlWriter) new DeencapsulationWriter(_xml) : new HtmlWriter(_xml, settings); var body = new Group(); foreach (var token in doc.Contents) { if (token is DefaultFontRef defaultFont) { _html.DefaultFont = doc.FontTable.TryGetValue(defaultFont.Value, out var font) ? font : doc.FontTable.FirstOrDefault().Value; } else if (token is DefaultTabWidth tabWidth) { _html.DefaultTabWidth = tabWidth.Value; } else if (token is Group group) { if (group.Destination?.Type != TokenType.HeaderTag) { body.Contents.Add(token); } } else if (token.Type != TokenType.HeaderTag) { body.Contents.Add(token); } } ToHtmlGroup(doc, body, true); RenderFootnotes(doc); _html.Close(); }
public static string ToHtml(RtfSource source, RtfHtmlSettings settings = null) { using (var stringWriter = new StringWriter()) { using (var writer = new HtmlTextWriter(stringWriter, settings)) { ToHtml(source, writer, settings); } return(stringWriter.ToString()); } }
/// <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(); }
public HtmlWriter(XmlWriter xmlWriter, RtfHtmlSettings settings) { _writer = xmlWriter; _settings = settings ?? new RtfHtmlSettings(); }