Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Highlighting/HtmlOptions.cs @ 12252

Last change on this file since 12252 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 2.7 KB
Line 
1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.IO;
21#if DOTNET4
22using System.Net;
23#else
24using System.Web;
25#endif
26
27namespace ICSharpCode.AvalonEdit.Highlighting
28{
29  /// <summary>
30  /// Holds options for converting text to HTML.
31  /// </summary>
32  public class HtmlOptions
33  {
34    /// <summary>
35    /// Creates a default HtmlOptions instance.
36    /// </summary>
37    public HtmlOptions()
38    {
39      this.TabSize = 4;
40    }
41   
42    /// <summary>
43    /// Creates a new HtmlOptions instance that copies applicable options from the <see cref="TextEditorOptions"/>.
44    /// </summary>
45    public HtmlOptions(TextEditorOptions options) : this()
46    {
47      if (options == null)
48        throw new ArgumentNullException("options");
49      this.TabSize = options.IndentationSize;
50    }
51   
52    /// <summary>
53    /// The amount of spaces a tab gets converted to.
54    /// </summary>
55    public int TabSize { get; set; }
56   
57    /// <summary>
58    /// Writes the HTML attribute for the style to the text writer.
59    /// </summary>
60    public virtual void WriteStyleAttributeForColor(TextWriter writer, HighlightingColor color)
61    {
62      if (writer == null)
63        throw new ArgumentNullException("writer");
64      if (color == null)
65        throw new ArgumentNullException("color");
66      writer.Write(" style=\"");
67      #if DOTNET4
68      WebUtility.HtmlEncode(color.ToCss(), writer);
69      #else
70      HttpUtility.HtmlEncode(color.ToCss(), writer);
71      #endif
72      writer.Write('"');
73    }
74   
75    /// <summary>
76    /// Gets whether the color needs to be written out to HTML.
77    /// </summary>
78    public virtual bool ColorNeedsSpanForStyling(HighlightingColor color)
79    {
80      if (color == null)
81        throw new ArgumentNullException("color");
82      return !string.IsNullOrEmpty(color.ToCss());
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.