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


C# HtmlDocument.CreateComment方法代码示例

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


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

示例1: Parse

        public void Parse(string input, string[] args = null)
        {
            var xxr = new XamlXmlReader(new StringReader(input), new XamlSchemaContext());
            var graphReader = new XamlObjectWriter(xxr.SchemaContext);

            while (xxr.Read())
                graphReader.WriteNode(xxr);

            var page = (Page)graphReader.Result;

            // Map our generators
            var g = new Generator();
            g.Map<Page, PageGeneratorBlock>();
            g.Map<Button, ButtonGeneratorBlock>();
            g.Map<StackPanel, StackPanelGeneratorBlock>();

            var doc = new HtmlDocument();
            var html = doc.CreateElement("html");

            g.Generate(html, page);
            // HTML5 Doc type
            doc.DocumentNode.AppendChild(doc.CreateComment("<!DOCTYPE html>"));
            doc.DocumentNode.AppendChild(html);

            doc.Save("test.htm");

            var cssContents = g.GenerateStyles(page);
            File.WriteAllText("XamlCore.css", cssContents);
        }
开发者ID:ncarrillo,项目名称:pantheon,代码行数:29,代码来源:Program.cs

示例2: Compile

        public string Compile(bool minify)
        {
            var js = jslastvalid;
            var html = htmllastvalid;

            // Merge fields
            var output = new StringBuilder(html);
            output.Replace("%resourcepath%", Program.BlobPathResource);
            output.Replace("%build%", Program.Config.Configuration.Build.ToString());
            output.Replace("%buildserial%", Program.Config.Configuration.BuildSerial.ToString());
            html = output.ToString();

            // Minify
            if (minify) {
                js = Minify.MinifyJS(js);
                html = Minify.MinifyHTML(html);
            }

            // Add JS
            var doc = new HtmlDocument();
            doc.LoadHtml(html);
            doc.GetElementbyId("_script_").AppendChild(doc.CreateComment(js));

            return doc.DocumentNode.OuterHtml;
        }
开发者ID:invertedtomato,项目名称:Amos2,代码行数:25,代码来源:Loader.cs

示例3: Html

        public static string Html(string value)
        {
            Contract.Requires(null != value, "value");

            // Load
            var doc = new HtmlDocument();
            doc.LoadHtml(value);

            // Minify all embeded CSS
            var styleNodes = doc.DocumentNode.SelectNodes("//style");
            if (null != styleNodes) {
                foreach (var item in styleNodes) {
                    item.InnerHtml = CascadingStyle(item.InnerHtml);
                }
            }

            // Strip comments
            var comments = doc.DocumentNode.SelectNodes("//comment()");
            if (null != comments) {
                foreach (var item in comments) {
                    if (item.InnerText.Substr(0, 9) != "<!DOCTYPE") {
                        item.Remove();
                    }
                }
            }

            // Minify all embeded JS
            var scriptNodes = doc.DocumentNode.SelectNodes("//script");
            if (null != scriptNodes) {
                foreach (var item in scriptNodes) {
                    var script = JavaScript(item.InnerHtml);
                    item.RemoveAllChildren();
                    item.AppendChild(doc.CreateComment(script));
                }
            }

            //https://github.com/markbeaton/TidyManaged ?

            // Convert back to string
            value = doc.DocumentNode.OuterHtml;

            value = Regex.Replace(value, @"\>\s+\<", "><", RegexOptions.Compiled | RegexOptions.Multiline);// Convert multiple concecutive spaces into one
            value = Regex.Replace(value, @"\s+", " ", RegexOptions.Compiled | RegexOptions.Multiline);// Convert multiple concecutive spaces into one
            value = Regex.Replace(value, @"^\s+", "", RegexOptions.Compiled | RegexOptions.Multiline);// Strip space at start of line
            value = Regex.Replace(value, "[\\r\\n]", string.Empty, RegexOptions.Compiled | RegexOptions.Multiline);// Strip newlines

            return value;
        }
开发者ID:invertedtomato,项目名称:AlphaCommon,代码行数:48,代码来源:Minification.cs

示例4: ConvertMathMl

		/// <summary>
		/// Converts the MathML blocks to be readable by OneNote
		/// </summary>
		/// <param name="htmlDoc"></param>
		private void ConvertMathMl(HtmlDocument htmlDoc)
		{
			HtmlNodeCollection mathNodes = htmlDoc.DocumentNode.SelectNodes("//math");
			if (mathNodes == null)
			{
				return;
			}

			foreach (var mathNode in mathNodes.ToList())
			{
				mathNode.Attributes.RemoveAll();
				HtmlAttribute mathMlNamespaceAttr = htmlDoc.CreateAttribute("xmlns:mml", MathMlNameSpace);
				mathNode.Attributes.Add(mathMlNamespaceAttr);

				foreach (var node in mathNode.DescendantsAndSelf())
				{
					node.Name = "mml:" + node.Name;
				}

				string newMathMlString = String.Format(MathMlOutline, mathNode.OuterHtml);
				HtmlCommentNode newMathNode = htmlDoc.CreateComment(newMathMlString);
				mathNode.ParentNode.ReplaceChild(newMathNode, mathNode);
			}
		}
开发者ID:OneNoteDev,项目名称:OneNoteConversionTool,代码行数:28,代码来源:EpubReader.cs

示例5: ParseEntity

 public static string ParseEntity(string entityHtml)
 {
     //HTML Agility pack drops closing option tags for some reason (bug?)
     HtmlNode.ElementsFlags.Remove("option");
     HtmlDocument html = new HtmlDocument();
     html.LoadHtml(String.Format("<html>{0}</html>", entityHtml));
     var entities = html.DocumentNode.SelectNodes("//*[@data-componentid]");
     var dummyTemplateId = NullUri;
     var dummyTemplateModified = Epoch;
     string isRepositoryPublished = "false";
     if (entities != null)
     {
         foreach (var entity in entities)
         {
             string compId = ReadAndRemoveAttribute(entity, "data-componentid");
             string compModified = ReadAndRemoveAttribute(entity, "data-componentmodified", Epoch);
             string templateId = ReadAndRemoveAttribute(entity, "data-componenttemplateid", NullUri);
             string templateModified = ReadAndRemoveAttribute(entity, "data-componenttemplatemodified", Epoch);
             // store template id as dummy default for next round (all our component templates generate the same output anyways)
             if (!templateId.Equals(NullUri))
             {
                 dummyTemplateId = templateId;
                 dummyTemplateModified = templateModified;
             }
             else
             {
                 // XPM does not like null uris for templates, so use defaults set before
                 templateId = dummyTemplateId;
                 templateModified = dummyTemplateModified;
                 // using a dummy template, so this should be considered a dynamic cp
                 isRepositoryPublished = IsQueryBased;
             }
             if (!String.IsNullOrEmpty(compId))
             {
                 HtmlCommentNode cpData = html.CreateComment(String.Format(ComponentPresentationFormat, compId, compModified, templateId, templateModified, isRepositoryPublished));
                 entity.ChildNodes.Insert(0, cpData);
             }
             //string lastProperty = "";
             //int index = 1;
             var properties = entity.SelectNodes("//*[@data-xpath]");
             if (properties != null && properties.Count > 0)
             {
                 foreach (var property in properties)
                 {
                     var xpath = ReadAndRemoveAttribute(property, "data-xpath");
                     //TODO index of mv fields
                     //index = propName == lastProperty ? index+1 : 1;
                     //lastProperty = propName;
                     HtmlCommentNode fieldData = html.CreateComment(String.Format(FieldFormat, xpath));
                     if (property.HasChildNodes)
                     {
                         property.ChildNodes.Insert(0, fieldData);
                     }
                     else
                     {
                         property.ParentNode.InsertBefore(fieldData, property);
                     }
                 }
             }
         }
     }
     return  html.DocumentNode.SelectSingleNode("/html").InnerHtml;
 }
开发者ID:MrSnowflake,项目名称:tri,代码行数:63,代码来源:TridionMarkup.cs

示例6: ParseRegion

        public static string ParseRegion(string regionHtml)
        {
            HtmlDocument html = new HtmlDocument();
            html.LoadHtml(String.Format("<html>{0}</html>", regionHtml));
            var entity = html.DocumentNode.SelectSingleNode("//*[@data-region]");
            if (entity != null)
            {
                string name = ReadAndRemoveAttribute(entity, "data-region");

                // TODO determine min occurs and max occurs for the region
                HtmlCommentNode regionData = html.CreateComment(MarkRegion(name));
                entity.ChildNodes.Insert(0, regionData);
            }
            return html.DocumentNode.SelectSingleNode("/html").InnerHtml;
        }
开发者ID:MrSnowflake,项目名称:tri,代码行数:15,代码来源:TridionMarkup.cs

示例7: injectScriptNotifyToHttpLink

		/// <summary>
		/// Replace http url link to ScriptNotify container in order to open IE in preview webview.
		/// </summary>
		/// <param name="content">A html content</param>
		/// <returns></returns>
		private static string injectScriptNotifyToHttpLink(string content)
		{
			var doc = new HtmlDocument();
			doc.LoadHtml(content);
			var headNode = doc.DocumentNode.FirstChild.FirstChild; // head tag
			if (headNode.Name.Equals("head"))
				Debug.WriteLine("head");

			// insert javascript function
			HtmlNode scriptElement = doc.CreateElement("script");
			scriptElement.Attributes.Add("type", "text/javascript");
			const string scriptContent = @"function gotoLink(args){ window.external.notify('url:' + args); return false;}";
			scriptElement.AppendChild(doc.CreateComment(scriptContent));
			headNode.AppendChild(scriptElement);

			// replace all a-tag. http://stackoverflow.com/a/23966320/361100
			foreach (HtmlNode node in doc.DocumentNode.FirstChild.Element("body").Descendants("a"))
			{
				if (node.Name.Equals("a"))
				{
					HtmlAttribute att = node.Attributes.FirstOrDefault(l => l.Name.Equals("href"));
					if (att != null)
					{
						node.Attributes.Add("onClick", String.Format("gotoLink('{0}');", att.Value));
						att.Value = "#";
					}
				}
			}
			return doc.DocumentNode.OuterHtml;
		}
开发者ID:modulexcite,项目名称:MarkPadRT,代码行数:35,代码来源:MainViewModel.cs


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