Ejemplo n.º 1
0
        public IActionResult Format(InputViewModel inputViewModel)
        {
            HtmlParserOptions htmlParserOptions = new HtmlParserOptions();
            var parser = new HtmlParser(htmlParserOptions);

            var document = parser.ParseDocument(inputViewModel.tbInput);

            var sw = new StringWriter();
            PrettyMarkupFormatter prettyMarkupFormatter = new PrettyMarkupFormatter();

            document.ToHtml(sw, prettyMarkupFormatter);

            var formattedHtml = sw.ToString();

            string guid = Guid.NewGuid().ToString();


            var result = new OutputViewModel()
            {
                RawHtml       = inputViewModel.tbInput,
                FormattedHtml = formattedHtml,
                Guid          = guid,
            };

            memoryCache.Set(guid, formattedHtml);

            return(Json(result));
        }
        static StringBuilder CleanSource(StringBuilder builder)
        {
            var       source = builder.ToString();
            var       parser = new HtmlParser();
            INodeList document;

            if (source.StartsWith("<!DOCTYPE html>", StringComparison.InvariantCultureIgnoreCase) ||
                source.StartsWith("<html>", StringComparison.InvariantCultureIgnoreCase))
            {
                document = parser.ParseFragment(source, null);
            }
            else
            {
                var dom = parser.ParseDocument("<html><body></body></html>");
                document = parser.ParseFragment(source, dom.Body);
            }

            builder.Clear();
            var formatter = new PrettyMarkupFormatter
            {
                Indentation = "  ",
                NewLine     = "\n"
            };

            using var writer = new StringWriter(builder);
            document.ToHtml(writer, formatter);
            writer.Flush();
            return(builder);
        }
Ejemplo n.º 3
0
        private static String Print(String html)
        {
            var document  = html.ToHtmlDocument();
            var formatter = new PrettyMarkupFormatter();

            return(document.ToHtml(formatter));
        }
Ejemplo n.º 4
0
        public static string ToHtmlPretty(this IElement element)
        {
            if (element == null)
            {
                return("<NULL>");
            }

            var sb        = new StringBuilder();
            var sw        = new StringWriter(sb);
            var formatter = new PrettyMarkupFormatter();

            element.ToHtml(sw, formatter);
            return(sb.ToString());
        }
Ejemplo n.º 5
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.º 6
0
        /// <summary>
        /// Uses the <see cref="PrettyMarkupFormatter"/> to generate a HTML markup string
        /// from a <see cref="IEnumerable{INode}"/> <paramref name="nodes"/>.
        /// </summary>
        public static string ToMarkup(this IEnumerable <INode> nodes)
        {
            if (nodes is null)
            {
                throw new ArgumentNullException(nameof(nodes));
            }

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

            nodes.ToHtml(sw, formatter);
            return(sw.ToString());
        }
Ejemplo n.º 7
0
        internal static async void GetGrass(string name)
        {
            if (TargetWebView == null || Equals(nameBuffer, name))
            {
                return;
            }
            if (name == null || name == "")
            {
                name = "AntiquePendulam";
            }
            var client = new HttpClient();
            var a      = await client.GetAsync($"https://github.com/users/{name}/contributions");

            var html = await a.Content.ReadAsStringAsync();

            var parser    = new HtmlParser();
            var sw        = new StringWriter();
            var formatter = new PrettyMarkupFormatter();

            try
            {
                var    content = parser.ParseDocument(html).GetElementsByTagName("svg")?.First().OuterHtml;
                string htmlStr;
                if (content == null)
                {
                    htmlStr = errorHtml;
                }
                else
                {
                    htmlStr = $"<html> <link href=\"https://fonts.googleapis.com/css?family=Quicksand\" rel=\"stylesheet\"> {style} <body bgcolor=\"{bg_color}\"> {content} </body> </html>";
                }
                TargetWebView.NavigateToString(htmlStr);
            }
            catch { }

            nameBuffer = name;
        }
Ejemplo n.º 8
0
        private static String Print(IDocument document)
        {
            var formatter = new PrettyMarkupFormatter();

            return(document.ToHtml(formatter));
        }