示例#1
0
        /// <summary>
        /// 获取文本编辑器提交到服务端存放的内容信息
        /// </summary>
        /// <param name="editor"></param>
        /// <returns></returns>
        public static InputContent GetInput(string source)
        {
            InputContent info = new InputContent()
            {
                OriginalCode = source, ImageKeys = new Stack <string>()
            };
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(source);
            ParseInput(doc.DocumentNode, info);
            info.Code = doc.DocumentNode.OuterHtml;
            return(info);
        }
示例#2
0
 private static void ParseInput(HtmlNode node, InputContent info)
 {
     for (var i = 0; i < node.ChildNodes.Count; i++)
     {
         var child = node.ChildNodes[i];
         if (child.Name == "img")
         {
             var src       = child.Attributes["src"].Value;
             var imageHost = DomainUtil.GetDomain("image");
             if (src.IndexOf(imageHost) > -1)
             {
                 //提取key
                 info.ImageKeys.Push(ImageUtil.ParseKey(src));
                 //重写地址
                 child.Attributes["src"].Value = src.Replace(imageHost, "[imageHost]");
             }
             //(?<=http://)[\w\.]+[^/]
         }
         ParseInput(child, info);
     }
 }