Пример #1
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());
        }
Пример #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());
        }
Пример #3
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());
        }
Пример #4
0
 public static string ToHtml(this IMarkupFormattable value)
 {
     return(value.ToHtml(new AngleSharp.Html.MinifyMarkupFormatter()));
 }
Пример #5
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));
 }
Пример #6
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);
Пример #7
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());
Пример #8
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());
Пример #9
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());
Пример #10
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);
Пример #11
0
 public static string ToText(this IMarkupFormattable markup) => markup.ToHtml(new TextFormatter()).Trim(' ').Trim('\t').Trim('\n');