HTML Tree.
The tree is static, it does not listen to OnTextChange. If you need dynamic tree, look at HtmlEditorTree in Microsoft.Html.Editor
Inheritance: IHtmlTreeVisitorPattern
Beispiel #1
0
	private MarkdownPage ParsePage(string fileName)
	{
		string html = CommonMark.CommonMarkConverter.Convert(File.ReadAllText(fileName));

		HtmlTree tree = new HtmlTree(new TextStream(html));
		tree.Build();

		ElementNode firstChild = tree.RootNode.Children[0];
		ElementNode prop = firstChild.Children[0];

		MarkdownPage page = new MarkdownPage();
		page.Title = AttrValue(prop, "pageTitle", Path.GetFileNameWithoutExtension(fileName));
		page.Description = AttrValue(prop, "description", page.Title);
		page.Content = html.Substring(firstChild.End, tree.RootNode.Length - firstChild.End).Trim();
		page.Keywords = AttrValue(prop, "keywords", page.Title);
		page.Slug = AttrValue(prop, "slug", page.Title.ToLowerInvariant());
		page.DateModified = File.GetLastWriteTime(fileName);
		page.FileName = fileName.Replace(BaseDirectory, string.Empty).Replace("\\", "/");
		page.ShowInMenu = Path.GetFileName(fileName).StartsWith("_") ? false : true;

		if (prop.GetAttribute("order") != null)
			page.Order = int.Parse(prop.GetAttribute("order").Value);
		else
			page.Order = 1000 + page.Title[0];

		return page;
	}
Beispiel #2
0
        public string WriteTree(HtmlTree tree) {
            _sb = new StringBuilder();
            _indent = 0;
            _tree = tree;

            RootNode root = tree.RootNode;

            foreach (TreeNode node in root.Children) {
                WriteNode(node);
            }

            string text = _sb.ToString();

            _sb = null;
            _tree = null;

            return text;
        }
Beispiel #3
0
        static public void BuildTree(HtmlTestFilesFixture fixture, string name) {
            string testFile = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".tree";
            string text = fixture.LoadDestinationFile(name);

            var tree = new HtmlTree(new TextStream(text), null, null, ParsingMode.Html);
            tree.Build();

            TreeWriter tw = new TreeWriter();
            string actual = tw.WriteTree(tree);

            if (_regenerateBaselineFiles) {
                // Update this to your actual enlistment if you need to update baseline
                baselineFile = Path.Combine(fixture.SourcePath, name) + ".tree";
                TestFiles.UpdateBaseline(baselineFile, actual);
            } else {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #4
0
        private void VerifyPositions(string html, HtmlPositionType[] positionTypes) {
            var tree = new HtmlTree(new TextStream(html), null, null, ParsingMode.Html);
            tree.Build();

            for (int i = 0; i < html.Length; i++) {
                ElementNode element;
                AttributeNode attribute;

                var pos = tree.RootNode.GetPositionElement(i, out element, out attribute);
                Assert.Equal(positionTypes[i], pos);
            }
        }
Beispiel #5
0
 private HtmlTree ParseHtml(string html) {
     HtmlParser parser = new HtmlParser();
     HtmlTree tree = new HtmlTree(new TextStream(html));
     tree.Build();
     return tree;
 }
Beispiel #6
0
        internal IReadOnlyList<INamedItemInfo> LoadFunctionInfoFromPackageHelpIndex() {
            List<INamedItemInfo> functions = new List<INamedItemInfo>();
            string content = null;

            try {
                string htmlFile = Path.Combine(this.InstallPath, this.Name, "html", "00index.html");
                if (File.Exists(htmlFile)) {
                    using (StreamReader sr = new StreamReader(htmlFile, Encoding.UTF8)) {
                        content = sr.ReadToEnd();
                    }
                }
            } catch (IOException) { }

            if (!string.IsNullOrEmpty(content)) {
                HtmlTree tree = new HtmlTree(new Microsoft.Web.Core.Text.TextStream(content));
                tree.Build();

                FunctionSearch functionSearch = new FunctionSearch(functions);
                tree.Accept(functionSearch, null);
            }

            Dictionary<string, INamedItemInfo> functionIndex = new Dictionary<string, INamedItemInfo>();
            foreach (INamedItemInfo ni in functions) {
                functionIndex[ni.Name] = ni;
            }

            IReadOnlyDictionary<string, string> mappedNames = GetMappedNames();
            foreach (string mappedName in mappedNames.Keys) {
                INamedItemInfo ni;
                string actualName = mappedNames[mappedName];
                if (functionIndex.TryGetValue(actualName, out ni)) {
                    INamedItemInfo niAlias = new NamedItemInfo() {
                        Name = mappedName,
                        Description = ni.Description,
                        ItemType = ni.ItemType
                    };
                    functions.Add(niAlias);
                }
            }

            return functions;
        }
Beispiel #7
0
        public void AttributeParsing_IncompleteTyping3() {
            var text = "<div lang=\"dir=\"ltr\">";
            var tree = new HtmlTree(new TextStream(text));

            tree.Build();

            var div = tree.RootNode.Children[0];
            Assert.Equal(2, div.Attributes.Count);

            Assert.Equal("lang", div.Attributes[0].Name);
            Assert.True(div.Attributes[0].HasValue());
            Assert.Equal(6, div.Attributes[0].ValueToken.Length);
            Assert.Equal('\"', div.Attributes[0].ValueToken.OpenQuote);
            Assert.Equal('\"', div.Attributes[0].ValueToken.CloseQuote);

            Assert.Equal("ltr\"", div.Attributes[1].Name);
            Assert.False(div.Attributes[1].HasValue());
        }
Beispiel #8
0
        public void AttributeParsing_IncompleteTyping1() {
            var text = "<div lang=dir=ltr>";
            var tree = new HtmlTree(new TextStream(text));

            tree.Build();

            var div = tree.RootNode.Children[0];
            Assert.Equal(2, div.Attributes.Count);

            Assert.Equal("lang", div.Attributes[0].Name);
            Assert.False(div.Attributes[0].HasValue());

            Assert.Equal("dir", div.Attributes[1].Name);
            Assert.True(div.Attributes[1].HasValue());

            Assert.Equal("ltr", div.Attributes[1].Value);
        }