Ejemplo n.º 1
0
 /// <summary>
 /// Writes the serialization of the node guided by the formatter to the
 /// given stream.
 /// </summary>
 /// <param name="markup">The markup node to format.</param>
 /// <param name="stream">The output stream to use.</param>
 public static async Task ToHtmlAsync(this IMarkupFormattable markup, Stream stream)
 {
     using (var writer = new StreamWriter(stream))
     {
         await markup.ToHtmlAsync(writer).ConfigureAwait(false);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Uses the <see cref="DiffMarkupFormatter"/> to generate a HTML markup string
        /// from a <see cref="IMarkupFormattable"/> <paramref name="markupFormattable"/>.
        /// The generated HTML markup will NOT include the internal Blazor attributes
        /// added to elements.
        /// </summary>
        public static string ToDiffMarkup(this IMarkupFormattable markupFormattable)
        {
            if (markupFormattable is null)
            {
                throw new ArgumentNullException(nameof(markupFormattable));
            }

            using var sw = new StringWriter();
            markupFormattable.ToHtml(sw, new DiffMarkupFormatter());
            return(sw.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the serialization of the node guided by the formatter.
        /// </summary>
        /// <param name="markup">The markup node to format.</param>
        /// <param name="formatter">The formatter to use.</param>
        /// <returns>The source code snippet.</returns>
        public static String ToHtml(this IMarkupFormattable markup, IMarkupFormatter formatter)
        {
            var sb = StringBuilderPool.Obtain();

            using (var writer = new StringWriter(sb))
            {
                markup.ToHtml(writer, formatter);
            }

            return(sb.ToPool());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Uses the <see cref="PrettyMarkupFormatter"/> to generate a HTML markup
        /// from a <see cref="IMarkupFormattable"/> <paramref name="markupFormattable"/>.
        /// </summary>
        public static string ToMarkup(this IMarkupFormattable markupFormattable)
        {
            if (markupFormattable is null)
            {
                throw new ArgumentNullException(nameof(markupFormattable));
            }

            using var sw = new StringWriter();
            var formatter = new PrettyMarkupFormatter()
            {
                NewLine     = Environment.NewLine,
                Indentation = "  "
            };

            markupFormattable.ToHtml(sw, formatter);
            return(sw.ToString());
        }
Ejemplo n.º 5
0
 public static string ToHtml(this IMarkupFormattable value)
 {
     return(value.ToHtml(new AngleSharp.Html.MinifyMarkupFormatter()));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates an instance of the <see cref="HtmlEqualException"/> type.
 /// </summary>
 public HtmlEqualException(IEnumerable <IDiff> diffs, IMarkupFormattable expected, IMarkupFormattable actual, string?userMessage)
     : base(PrintHtml(expected), PrintHtml(actual), CreateUserMessage(diffs, userMessage), "Expected HTML", "Actual HTML")
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns the (complete) HTML markup representation of the node.
 /// </summary>
 /// <param name="markup">The markup node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String ToHtml(this IMarkupFormattable markup)
 {
     return(markup.ToHtml(HtmlMarkupFormatter.Instance));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Returns the (complete) HTML markup representation of the node.
 /// </summary>
 /// <param name="markup">The markup node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String ToHtml(this IMarkupFormattable markup) =>
 markup.ToHtml(HtmlMarkupFormatter.Instance);
Ejemplo n.º 9
0
 /// <summary>
 /// Writes the serialization of the node guided by the formatter.
 /// </summary>
 /// <param name="markup">The markup node to format.</param>
 /// <param name="writer">The output target of the serialization.</param>
 public static Task ToHtmlAsync(this IMarkupFormattable markup, TextWriter writer) =>
 writer.WriteAsync(markup.ToHtml());
Ejemplo n.º 10
0
 /// <summary>
 /// Returns a prettified serialization of the node guided by the
 /// PrettyMarkupFormatter with the default options.
 /// </summary>
 /// <param name="markup">The markup node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String Prettify(this IMarkupFormattable markup) =>
 markup.ToHtml(new PrettyMarkupFormatter());
Ejemplo n.º 11
0
 /// <summary>
 /// Returns a minified serialization of the node guided by the
 /// MinifyMarkupFormatter with the default options.
 /// </summary>
 /// <param name="markup">The markup node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String Minify(this IMarkupFormattable markup) =>
 markup.ToHtml(new MinifyMarkupFormatter());
Ejemplo n.º 12
0
 /// <summary>
 /// Writes the serialization of the node guided by the formatter.
 /// </summary>
 /// <param name="markup">The markup node to format.</param>
 /// <param name="writer">The output target of the serialization.</param>
 public static void ToHtml(this IMarkupFormattable markup, TextWriter writer) =>
 markup.ToHtml(writer, HtmlMarkupFormatter.Instance);
Ejemplo n.º 13
0
 public static string ToText(this IMarkupFormattable markup) => markup.ToHtml(new TextFormatter()).Trim(' ').Trim('\t').Trim('\n');
Ejemplo n.º 14
0
 public static string PrintHtml(this IMarkupFormattable nodes) => nodes.ToDiffMarkup() + Environment.NewLine;