当前位置: 首页>>代码示例>>C#>>正文


C# HtmlDocument.CreateTextNode方法代码示例

本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.CreateTextNode方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.CreateTextNode方法的具体用法?C# HtmlDocument.CreateTextNode怎么用?C# HtmlDocument.CreateTextNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlAgilityPack.HtmlDocument的用法示例。


在下文中一共展示了HtmlDocument.CreateTextNode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public void Process([NotNull] RenderFieldArgs args)
        {
            if (args.FieldTypeKey != "rich text") return;

            if (Settings.DoNotExpandInLiveSite && Context.PageMode.IsNormal) return;
            
            var document = new HtmlDocument();
            document.LoadHtml(args.Result.FirstPart);
            var htmlNodeCollection = document.DocumentNode.SelectNodes("//span[@itemid]");
            
            if (htmlNodeCollection == null)
                return;
            
            foreach (var node in htmlNodeCollection)
            {
                var item = Context.Database.GetItem(node.Attributes["itemid"].Value);
                if (item == null) continue;

                var fieldValue = item[node.Attributes["field"].Value];

                if(Context.PageMode.IsNormal)
                {
                    var newnode = document.CreateTextNode(fieldValue);
                    node.ParentNode.ReplaceChild(newnode, node);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(fieldValue)) node.InnerHtml = fieldValue;

                    if (Context.PageMode.IsPageEditorEditing)
                    {
                        node.SetAttributeValue("style",Settings.SnippetStyle);
                    }    
                }
                
            }
            args.Result.FirstPart = document.DocumentNode.OuterHtml;
        }
开发者ID:Sitecore,项目名称:Sitecore.Labs.Snippets,代码行数:38,代码来源:ExpandSnippets.cs

示例2: ProcessCodeTags

 private static void ProcessCodeTags(HtmlDocument doc, Guid productID)
 {
     HtmlTextNode textNode;
     HtmlNodeCollection scripts = doc.DocumentNode.SelectNodes("//code");
     if (scripts != null)
     {
         foreach (HtmlNode node in scripts)
         {
             textNode = doc.CreateTextNode(Highlight.HighlightToHTML(node.InnerHtml, GetLanguage(node), true).Replace(@"class=""codestyle""", string.Format(@"class=""codestyle"" _wikiCodeStyle=""{0}""", GetLanguageAttrValue(node))));
             node.ParentNode.ReplaceChild(textNode, node);
         }
     }
 }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:13,代码来源:HtmlUtility.cs

示例3: HighLightCode

        private static string HighLightCode(string source)
        {
            //Escape HTML Symbols in code Tags

            var mcCode = rexCode.Matches(source);
            foreach (Match m in mcCode)
            {
                try
                {
                    var sCode = m.Groups[1].Value.Substring(m.Groups[1].Value.IndexOf(">", StringComparison.Ordinal) + 1);
                    source = source.Replace(sCode, EscapeHtml(sCode));
                }
                catch (Exception)
                {
                }
            }

            try
            {
                var doc = new HtmlDocument();
                doc.LoadHtml(source);
                var scripts = doc.DocumentNode.SelectNodes("//code");
                if (scripts != null)
                {
                    foreach (var node in scripts)
                    {
                        var textNode = doc.CreateTextNode(Highlight.HighlightToHTML(node.InnerHtml, GetLanguage(node), true).Replace(@"class=""codestyle""", string.Format(@"class=""codestyle"" _wikiCodeStyle=""{0}""", GetLanguageAttrValue(node))));
                        node.ParentNode.ReplaceChild(textNode, node);
                    }
                }
                return doc.DocumentNode.InnerHtml;
            }
            catch (Exception)
            {
                return source;
            }
        }
开发者ID:haoasqui,项目名称:ONLYOFFICE-Server,代码行数:37,代码来源:HtmlWikiUtil_Wiki2Html.cs.cs

示例4: CreateNodeWithTextContent

 HtmlNode CreateNodeWithTextContent(HtmlDocument doc, string elementTitle, string text)
 {
     HtmlNode node = doc.CreateElement(elementTitle);
     node.AppendChild(doc.CreateTextNode(text));
     return node;
 }
开发者ID:AlertProject,项目名称:Text-processing-bundle,代码行数:6,代码来源:KEUI.Annotation.cs

示例5: MakeNode

        private HtmlNode MakeNode(HtmlDocument doc, string tag, string mainAttr, string mainValue, Dictionary<string, string> createAttributes)
        {
            // can't create a new node for a script where the value is its id
            if (mainAttr == "src" && Regex.IsMatch(mainValue.ToLower(), "^[a-z][a-z0-9_\\-]*$"))
                return null;

            HtmlNode newNode = doc.CreateElement(tag);
            if (mainValue.StartsWith("javascript:"))
                newNode.AppendChild(doc.CreateTextNode(mainValue.After("javascript:")));
            else
                newNode.Attributes.Add(doc.CreateAttribute(mainAttr, mainValue));
            foreach (KeyValuePair<string, string> kvp in createAttributes)
                newNode.Attributes.Add(doc.CreateAttribute(kvp.Key, kvp.Value));
            return newNode;
        }
开发者ID:jamesej,项目名称:lynicon,代码行数:15,代码来源:IncludesManager.cs

示例6: GenerateHTML

        /// <summary>
        /// Traverse the directory structure present in provided DirectoryModel and
        /// create HTML that will represent the directories and files that are found.
        /// </summary>
        /// <param name="directory">Directory containing subdirectories and articles.</param>
        /// <param name="listFileDoc">Object representing HTML document.</param>
        /// <param name="directoryDiv">Container representing div that will contain categories and articles.</param>
        /// <param name="isSourceDir">Bool representing whether directoryDiv, is parent directory of article directory structure.</param>
        static void GenerateHTML(DirectoryModel directory, HtmlDocument listFileDoc, HtmlNode directoryContainerDiv, 
            bool isSourceDir, ref int index, string categoriesUrlText)
        {
            // Hash directory path to be used as unique identifier for
            // folder div's id attribute
            index++;
            string encryptedPath = EncryptStrings.EncryptToMD5String(directory.Path);

            // Create div that will hold folder icon and directory name
            HtmlNode directoryDiv = listFileDoc.CreateElement("div");

            // Container for categories (subdirectories) and article links.
            directoryDiv.SetAttributeValue("class", "directory");
            directoryDiv.SetAttributeValue("id", encryptedPath);

            // Check whether or not current directory, is the parent node
            // of article directory structure (as this is first container to be seen)
            string style = isSourceDir ? String.Format("z-index: {0};", index) : String.Format("z-index: -{0}; display: none", index);
            directoryDiv.SetAttributeValue("style", style);

            // div to hold category header and links to roll back to previous views
            HtmlNode directoryCategoryContainer = listFileDoc.CreateElement("div");
            directoryCategoryContainer.SetAttributeValue("id", "category-container");

            // header for category section of directory div
            HtmlNode directoryHeader = listFileDoc.CreateElement("h2");
            directoryHeader.SetAttributeValue("class", "category-headers");

            // add text node for header
            HtmlNode categoryHeaderText = listFileDoc.CreateTextNode("Categories");
            directoryHeader.AppendChild(categoryHeaderText);
            directoryCategoryContainer.AppendChild(directoryHeader);

            // create div to hold category urls used to roll back to a
            //previous view
            HtmlNode categoryUrlDiv = listFileDoc.CreateElement("div");
            categoryUrlDiv.SetAttributeValue("class", "visited-categories-container");

            // add category url text
            HtmlNode categoryUrlText = listFileDoc.CreateTextNode(categoriesUrlText);
            categoryUrlDiv.AppendChild(categoryUrlText);
            directoryCategoryContainer.AppendChild(categoryUrlDiv);

            // add container for category header and links for rolling back to particular views
            // to the directory container div
            directoryDiv.AppendChild(directoryCategoryContainer);

            HtmlNode categoryRule = listFileDoc.CreateElement("hr");
            categoryRule.SetAttributeValue("class", "header-rule");
            directoryDiv.AppendChild(categoryRule);

            // update current url string to be used by subordinate categories
            string currentUrlName = Path.GetFileName(directory.Path);

            if (categoriesUrlText == String.Empty)
            {
                categoriesUrlText += @"<a href='#' onclick='rollBack("""")'>Home</a>";
            }
            else
            {
                categoriesUrlText += @" > <a href='#' onclick='rollBack(""" + encryptedPath + @""")'>" +
                                    currentUrlName + "</a>";
            }

            // Process subdirectories' contents and generate relevant
            // html.
            if (directory.Subdirectories.Count > 0)
            {
                foreach (DirectoryModel subdirectory in directory.Subdirectories)
                {
                    isSourceDir = false;

                    HtmlNode subDirectoryDiv = listFileDoc.CreateElement("div");
                    subDirectoryDiv.SetAttributeValue("class", "subdirectory");
                    subDirectoryDiv.SetAttributeValue("name", EncryptStrings.EncryptToMD5String(subdirectory.Path));
                    subDirectoryDiv.SetAttributeValue("onclick", "bringToFront(this)");

                    HtmlNode folderParagraph = listFileDoc.CreateElement("p");
                    folderParagraph.SetAttributeValue("class", "folder-name");

                    HtmlTextNode text = listFileDoc.CreateTextNode(Path.GetFileName(subdirectory.Path));
                    folderParagraph.AppendChild(text);

                    subDirectoryDiv.AppendChild(folderParagraph);

                    directoryDiv.AppendChild(subDirectoryDiv);

                    GenerateHTML(subdirectory, listFileDoc, directoryContainerDiv, isSourceDir, ref index, categoriesUrlText);
                }
            }

            // Container for links to show articles.
//.........这里部分代码省略.........
开发者ID:philspain,项目名称:KBLite,代码行数:101,代码来源:ConvertToHtml.cs

示例7: GetExternalReferencesListNode

        private static HtmlNode GetExternalReferencesListNode(
            HtmlDocument document,
            IEnumerable<ExternalReference> externalReferences)
        {
            var list = document.CreateElement("ol");
            foreach (var reference in externalReferences)
            {
                var item = document.CreateElement("li");

                string referenceId = GetExternalReferenceId(reference.Index);

                var backLink = document.CreateElement("a");
                backLink.InnerHtml = "<strong>^</strong>";
                backLink.SetAttributeValue("href", "#" + referenceId + BackLinkReferenceIdSuffix);

                var externalLink = document.CreateElement("a");
                externalLink.InnerHtml = reference.Url;
                externalLink.SetAttributeValue("href", reference.Url);
                externalLink.SetAttributeValue("name", referenceId);

                item.AppendChild(backLink);
                item.AppendChild(document.CreateTextNode(" "));
                item.AppendChild(externalLink);

                list.AppendChild(item);
            }

            return list;
        }
开发者ID:sebnilsson,项目名称:WikiDown,代码行数:29,代码来源:ExternalReferencesConverterHook.cs

示例8: GetAppPage


//.........这里部分代码省略.........
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute submit_attr = htmlDoc.CreateAttribute("submit", submit);
                            new_node.Attributes.Append(submit_attr);

                            //align=\"center\"
                            HtmlAttribute align_attr = htmlDoc.CreateAttribute("align", "center");
                            new_node.Attributes.Append(align_attr);

                            //<img src=\"https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png\" style=\"width:100%;height:100%\" />
                            HtmlNode img_node = htmlDoc.CreateElement("img");
                            HtmlAttribute img_src_attr = null;
                            if (field_map["image_source"] != null)
                                img_src_attr = htmlDoc.CreateAttribute("src", field_map["image_source"].ToString());
                            else
                                img_src_attr = htmlDoc.CreateAttribute("src", "https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png");

                            img_node.Attributes.Append(img_src_attr);

                            HtmlAttribute img_style_attr = htmlDoc.CreateAttribute("style", "width:100%;height:100%");
                            img_node.Attributes.Append(img_style_attr);
                            new_node.AppendChild(img_node);

                            //<p style=\"position:relative;top:-38px;\">{2}</p>
                            HtmlNode p_node = htmlDoc.CreateElement("p");
                            HtmlNode text_node = null;
                            if (field_map["text"] != null)
                                text_node = htmlDoc.CreateTextNode(field_map["text"].ToString());
                            else
                                text_node = htmlDoc.CreateTextNode("");

                            p_node.AppendChild(text_node);
                            //top = (-ph/2) -(3*ah/2);
                            int height = Convert.ToInt32(field_map["height"].ToString());
                            int font_size = Convert.ToInt32(field_map["font_size"].ToString());
                            int top = (-height / 2) - (3 * font_size / 2);
                            HtmlAttribute style_attr = htmlDoc.CreateAttribute("style", "position:relative;top:" + top.ToString() + "px;");
                            p_node.Attributes.Append(style_attr);
                            new_node.AppendChild(p_node);
                            break;
                        case "image_button": //"<div title=\"MobiFlex ImageButton\"  style=\"{3}\" id=\"{0}\"  submit=\"{2}\"><img src=\"{1}\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex ImageButton";
                            string image_button_url = field_map["image_source"].ToString();
                            if (!field_map.ContainsKey("width")) //the xml does not have the width and height so use the width and height of the actual image
                            {
                                Size size = util.GetImageSize(image_button_url);
                                if (size != null)
                                {
                                    new_node.Attributes["style"].Value += "width:" + size.Width.ToString() + "px;height:" + size.Height.ToString() + "px;";
                                }
                            }
                            AddImageNode(htmlDoc, new_node, image_button_url);

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string image_button_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:67,代码来源:XmlUtil.cs

示例9: LoadHtml

        /// <summary>
        /// Loads the HTML.
        /// </summary>
        /// <param name="inputUri">The input URI.</param>
        /// <returns>
        /// The loaded HTML from the specified input URI.
        /// </returns>
        public Task<string> LoadHtml(string inputUri)
        {
            return new Task<string>(
                () =>
                {
                    if (string.IsNullOrWhiteSpace(inputUri))
                    {
                        return "<html><head></head><body></body></html>";
                    }

                    var htmlDocument = new HtmlDocument();
                    var request = (HttpWebRequest)WebRequest.Create(inputUri);
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            using (var receiveStream = response.GetResponseStream())
                            {
                                StreamReader readStream = null;

                                if (response.CharacterSet == null)
                                {
                                    readStream = new StreamReader(receiveStream);
                                }
                                else
                                {
                                    readStream = new StreamReader(
                                        receiveStream, Encoding.GetEncoding(response.CharacterSet));
                                }

                                htmlDocument.Load(readStream.BaseStream, false);
                                readStream.Close();
                            }
                        }
                    }

                    if ((htmlDocument.DocumentNode == null) ||
                        string.IsNullOrWhiteSpace(htmlDocument.DocumentNode.InnerHtml))
                    {
                        return "<html><head></head><body><h1>Load error!</h1><br/><h3>Error without description or unknown.</h3></body></html>";
                    }

                    var noErrorScriptHtml =
                        "<script type=\"text/javascript\">function noError(){return true;} window.onerror=noError;</script>";

                    var headNode = htmlDocument.DocumentNode.SelectSingleNode("//head");

                    headNode.InsertBefore(
                        htmlDocument.CreateTextNode(noErrorScriptHtml),
                        headNode.FirstChild);

                    var bodyNode = htmlDocument.DocumentNode.SelectSingleNode("//body");

                    bodyNode.InsertBefore(
                        htmlDocument.CreateTextNode(noErrorScriptHtml),
                        bodyNode.FirstChild);

                    var htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"content\"]");

                    var nodesToRemove = new List<HtmlNode>();

                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"jp-post-flair\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"sidebar-after-singular\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"comments-template\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"footer\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"sidebar-primary\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"bit\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@class=\"wpcnt\"]"));

                    foreach (var nodeToRemove in nodesToRemove.Where(node => (node != null)))
                    {
                        nodeToRemove.Remove();
                    }

                    var linkNodes = htmlDocument.DocumentNode.SelectNodes("//a");

                    foreach (var linkNode in linkNodes)
                    {
                        linkNode.SetAttributeValue("target", "_blank");
                    }

                    if (htmlNode != null)
                    {
                        htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class=\"entry-content\"]");

                        bodyNode.RemoveAllChildren();
                        bodyNode.AppendChild(htmlNode);
                    }

                    return htmlDocument.DocumentNode.InnerHtml;
                });
        }
开发者ID:davidop,项目名称:ComposedUI-PrismLibrary,代码行数:99,代码来源:RSSService.cs


注:本文中的HtmlAgilityPack.HtmlDocument.CreateTextNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。