static string NormalizeForComparison(string text)
        {
            var doc = HtmlDocumentFragment.Parse(text, null);

            DomNodeVisitor.Visit(doc, new NormalizeWSVisitor());
            return(doc.OuterHtml);
        }
        public void OwnerDocument_initializes_with_Html5_by_default()
        {
            var frag = new HtmlDocumentFragment();

            Assert.NotNull(frag.OwnerDocument.Schema);
            Assert.Equal("html5", frag.OwnerDocument.Schema.LocalName);
        }
        public void InnerHtml_should_replace_contents()
        {
            var frag = new HtmlDocumentFragment();

            frag.InnerHtml = "<div><br><br></div>";
            Assert.HasCount(1, frag.ChildNodes);
            Assert.Equal("<div>\n <br>\n <br>\n</div>", frag.InnerHtml);
        }
        public void Parse_should_support_several_nodes()
        {
            var settings = new HtmlReaderSettings {
                Mode = HtmlTreeBuilderMode.Xml,
            };
            var xml  = "<a/><b/><c hello=\"world\"/>";
            var frag = HtmlDocumentFragment.Parse(xml, settings);

            Assert.HasCount(3, frag.ChildNodes);
            Assert.Equal(new [] { "a", "b", "c" }, frag.ChildNodes.Select(n => n.NodeName));
        }
        public void Parse_should_handle_script_as_data()
        {
            HtmlDocument         doc2 = new HtmlDocument();
            HtmlDocumentFragment doc  = HtmlDocumentFragment.Parse(
                "<script>\"hello\"</script>", null
                );

            Assert.Equal("script", doc.ChildNode(0).NodeName);

            Assert.Equal(DomNodeType.Text, doc.ChildNode(0).ChildNode(0).NodeType);

            Assert.True(((HtmlText)doc.ChildNode(0).ChildNode(0)).IsData);
        }
Exemple #6
0
        public ParsedTemplate(string text, string name, HxlCompilerSettings settings)
        {
            _metrics = Metrics.ForTemplateParsing();
            _metrics.StartParsing();
            _sourceDocument = HtmlDocumentFragment.Parse(text, new HtmlReaderSettings {
                Mode = HtmlTreeBuilderMode.Xml
            });
            _metrics.EndParsing(name, text.Length);

            _settings    = settings;
            _nodeFactory = DomNodeFactory.Compose(
                HxlDomNodeFactory.Compiler,
                _settings.NodeFactories,
                new InvalidFactory());

            Signature = string.Concat(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(text))
                                      .Take(8)
                                      .Select(b => b.ToString("x2"))
                                      );

            if (string.IsNullOrEmpty(name))
            {
                this.TemplateName = "Template" + this.Signature;
            }
            else
            {
                this.TemplateName = CodeUtility.Slug(name);
            }

            this.Namespace = "Generated";
            this.ClassName = this.TemplateName;

            using (UsingNamespaceResolver()) {
                this._preparedDocument = PrepareDocument();
            }
        }
Exemple #7
0
 internal HtmlTemplateElement(string namespaceUri,
                              IEnumerable <HtmlAttribute> attributes,
                              HtmlDocumentFragment content) :
     base(HTML.TAG_NAMES.TEMPLATE, namespaceUri, attributes) => Content = content;
 public void SetTemplateContent(HtmlTemplateElement templateElement, HtmlDocumentFragment content) =>
 templateElement.Content = content;
        static string ParseHtml(string text)
        {
            var doc = HtmlDocumentFragment.Parse(text, null);

            return(doc.OuterHtml);
        }