zoukankan      html  css  js  c++  java
  • 修改BlogEngine.NET:给摘要显示添加图片显示的另一种方法

    方法如下:

    打开theme目录下面的PostView.ascx文件。

    定位到<asp:PlaceHolder ID="BodyContent" runat="server" />

    在之前添加一点代码<%= getImage(base.ShowExcerpt,Post.Content) %>

    修改完即成如下:

    <div class="entry"><%= getImage(base.ShowExcerpt,Post.Content) %><asp:PlaceHolder ID="BodyContent" runat="server" /></div>

    当然别忘了getImage()函数的代码要加进去,PostView.ascx文件的最后添加一段:

     <script language="CS" runat="server">
     
          string getImage(bool ShowExcerpt, string input)
          {
              if (!ShowExcerpt || input == null)
                  return "";
     
                string pain = input;//字符串
                string pattern = @"<img(.|\n)+?>";
     
                System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, pattern, 
                    System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);
                if (m.Success)
                {
                    string src = getSrc (m.Value);
                    string img = string.Format("<img align=\"right\" style=\"border-bottom: 0px; border-left: 0px; display: inline; margin-left: 5px; border-top: 0px; margin-right: 5px; border-right: 0px\" border=\"0\" width=\"100\" {0}  />",src);
                    return img;
                }
                else
                {
                    return "";
                }
                
            }
     
            string getSrc(string input)
            {           
                string pattern = "src=[\'|\"](.+?)[\'|\"]";
     
                System.Text.RegularExpressions.Regex reImg = new System.Text.RegularExpressions.Regex(pattern, 
                    System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);
                System.Text.RegularExpressions.Match mImg = reImg.Match(input);
                if (mImg.Success)
                {
                    return mImg.Value;
                }
                return "";
             
            }
       </script>
  • 相关阅读:
    linux source
    C和指针 第七章 习题
    C和指针 第七章 可变参数
    C和指针 第七章 函数递归与迭代
    C和指针 第五章 位数组
    C和指针 第六章 习题
    Net core学习系列(六)——Net Core路由
    Net core学习系列(五)——Net Core应用程序Startup类介绍
    Net core学习系列(四)——Net Core项目执行流程
    Net core学习系列(三)——Net Core中的依赖注入
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/1799523.html
Copyright © 2011-2022 走看看