From feabbc7e1bda53d29b1c2e7eb965c92920955eef Mon Sep 17 00:00:00 2001 From: wook Date: Mon, 8 May 2017 21:40:38 +0900 Subject: [PATCH] init --- HTMLParser.Example/Global.asax | 1 + HTMLParser.Example/Global.asax.cs | 16 ++ HTMLParser.Example/HTMLParser.Example.csproj | 141 ++++++++++++++++++ HTMLParser.Example/Parsed.aspx | 32 ++++ HTMLParser.Example/Parsed.aspx.cs | 29 ++++ HTMLParser.Example/Parsed.aspx.designer.cs | 69 +++++++++ HTMLParser.Example/Properties/AssemblyInfo.cs | 35 +++++ HTMLParser.Example/Web.Debug.config | 30 ++++ HTMLParser.Example/Web.Release.config | 31 ++++ HTMLParser.Example/Web.config | 21 +++ HTMLParser.Example/packages.config | 5 + HTMLParser.sln | 6 + HTMLParser/Class1.cs | 8 - HTMLParser/ParserEx.cs | 33 ++++ 14 files changed, 449 insertions(+), 8 deletions(-) create mode 100644 HTMLParser.Example/Global.asax create mode 100644 HTMLParser.Example/Global.asax.cs create mode 100644 HTMLParser.Example/HTMLParser.Example.csproj create mode 100644 HTMLParser.Example/Parsed.aspx create mode 100644 HTMLParser.Example/Parsed.aspx.cs create mode 100644 HTMLParser.Example/Parsed.aspx.designer.cs create mode 100644 HTMLParser.Example/Properties/AssemblyInfo.cs create mode 100644 HTMLParser.Example/Web.Debug.config create mode 100644 HTMLParser.Example/Web.Release.config create mode 100644 HTMLParser.Example/Web.config create mode 100644 HTMLParser.Example/packages.config delete mode 100644 HTMLParser/Class1.cs create mode 100644 HTMLParser/ParserEx.cs diff --git a/HTMLParser.Example/Global.asax b/HTMLParser.Example/Global.asax new file mode 100644 index 0000000..ef9bd06 --- /dev/null +++ b/HTMLParser.Example/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.cs" Inherits="HTMLParser.Example.Global" Language="C#" %> diff --git a/HTMLParser.Example/Global.asax.cs b/HTMLParser.Example/Global.asax.cs new file mode 100644 index 0000000..de086e9 --- /dev/null +++ b/HTMLParser.Example/Global.asax.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Security; +using System.Web.SessionState; + +namespace HTMLParser.Example +{ + public class Global : System.Web.HttpApplication + { + protected void Application_Start(object sender, EventArgs e) + { + } + } +} \ No newline at end of file diff --git a/HTMLParser.Example/HTMLParser.Example.csproj b/HTMLParser.Example/HTMLParser.Example.csproj new file mode 100644 index 0000000..e0125cd --- /dev/null +++ b/HTMLParser.Example/HTMLParser.Example.csproj @@ -0,0 +1,141 @@ + + + + + + Debug + AnyCPU + + + 2.0 + {40A82F71-B960-46A7-ABFB-51624688A52A} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + HTMLParser.Example + HTMLParser.Example + v4.5.2 + true + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + true + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + False + ..\HTMLParser\bin\Release\netstandard1.4\HTMLParser.dll + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + + + + + + + + + + + + + + + + + + + + + + Web.config + + + Web.config + + + + + + + + + + Global.asax + + + Parsed.aspx + ASPXCodeBehind + + + Parsed.aspx + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 7207 + / + http://localhost:7207/ + False + False + + + False + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/HTMLParser.Example/Parsed.aspx b/HTMLParser.Example/Parsed.aspx new file mode 100644 index 0000000..eaeeab2 --- /dev/null +++ b/HTMLParser.Example/Parsed.aspx @@ -0,0 +1,32 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Parsed.aspx.cs" Inherits="HTMLParser.Example.Parsed" %> + + + + + + + + + +
+ source
+
+ + url parsed +
 
+ + youtube parsed +
 
+ + url and youtube parsed +
 
+ + + + + diff --git a/HTMLParser.Example/Parsed.aspx.cs b/HTMLParser.Example/Parsed.aspx.cs new file mode 100644 index 0000000..44963d0 --- /dev/null +++ b/HTMLParser.Example/Parsed.aspx.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +using HTMLParser; +using System.Text.RegularExpressions; + +namespace HTMLParser.Example +{ + public partial class Parsed : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + } + + protected void Button1_Click(object sender, EventArgs e) + { + ParserEx parse = new ParserEx(); + + this.ParsedUrl.InnerHtml = parse.ParseUrl(this.txtSource.Value); + this.parsedYoutube.InnerHtml = parse.ParseYoutube(this.txtSource.Value); + this.parsedUrlAndYoutube.InnerHtml = parse.ParseUrlAndYoutube(this.txtSource.Value); + } + + } +} \ No newline at end of file diff --git a/HTMLParser.Example/Parsed.aspx.designer.cs b/HTMLParser.Example/Parsed.aspx.designer.cs new file mode 100644 index 0000000..ba78948 --- /dev/null +++ b/HTMLParser.Example/Parsed.aspx.designer.cs @@ -0,0 +1,69 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace HTMLParser.Example { + + + public partial class Parsed { + + /// + /// form1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// + /// txtSource control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlTextArea txtSource; + + /// + /// ParsedUrl control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl ParsedUrl; + + /// + /// parsedYoutube control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl parsedYoutube; + + /// + /// parsedUrlAndYoutube control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl parsedUrlAndYoutube; + + /// + /// Button1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button Button1; + } +} diff --git a/HTMLParser.Example/Properties/AssemblyInfo.cs b/HTMLParser.Example/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..143e476 --- /dev/null +++ b/HTMLParser.Example/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("HTMLParser.Example")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("HTMLParser.Example")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("40a82f71-b960-46a7-abfb-51624688a52a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/HTMLParser.Example/Web.Debug.config b/HTMLParser.Example/Web.Debug.config new file mode 100644 index 0000000..fae9cfe --- /dev/null +++ b/HTMLParser.Example/Web.Debug.config @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/HTMLParser.Example/Web.Release.config b/HTMLParser.Example/Web.Release.config new file mode 100644 index 0000000..da6e960 --- /dev/null +++ b/HTMLParser.Example/Web.Release.config @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/HTMLParser.Example/Web.config b/HTMLParser.Example/Web.config new file mode 100644 index 0000000..855dd25 --- /dev/null +++ b/HTMLParser.Example/Web.config @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HTMLParser.Example/packages.config b/HTMLParser.Example/packages.config new file mode 100644 index 0000000..b23732c --- /dev/null +++ b/HTMLParser.Example/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/HTMLParser.sln b/HTMLParser.sln index 08212a9..7758c6f 100644 --- a/HTMLParser.sln +++ b/HTMLParser.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26403.7 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTMLParser", "HTMLParser\HTMLParser.csproj", "{0D713178-8D10-4521-BA52-DA3B3F5071CD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTMLParser.Example", "HTMLParser.Example\HTMLParser.Example.csproj", "{40A82F71-B960-46A7-ABFB-51624688A52A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {0D713178-8D10-4521-BA52-DA3B3F5071CD}.Debug|Any CPU.Build.0 = Debug|Any CPU {0D713178-8D10-4521-BA52-DA3B3F5071CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {0D713178-8D10-4521-BA52-DA3B3F5071CD}.Release|Any CPU.Build.0 = Release|Any CPU + {40A82F71-B960-46A7-ABFB-51624688A52A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40A82F71-B960-46A7-ABFB-51624688A52A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40A82F71-B960-46A7-ABFB-51624688A52A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40A82F71-B960-46A7-ABFB-51624688A52A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HTMLParser/Class1.cs b/HTMLParser/Class1.cs deleted file mode 100644 index ecafacd..0000000 --- a/HTMLParser/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace HTMLParser -{ - public class Class1 - { - } -} diff --git a/HTMLParser/ParserEx.cs b/HTMLParser/ParserEx.cs new file mode 100644 index 0000000..3a03f2c --- /dev/null +++ b/HTMLParser/ParserEx.cs @@ -0,0 +1,33 @@ +using System; +using System.Text.RegularExpressions; + +namespace HTMLParser +{ + public class ParserEx + { + public string ParseUrl(string article) + { + if (string.IsNullOrEmpty(article)) return string.Empty; + + string Pttrn = @"(((http|https|ftp|telnet|news)://|www\.)[^youtube][a-z0-9-]+.[][a-zA-Z0-9:&#@=_~%;?/.+-]+)"; + string Lnk = "$1"; + + return Regex.Replace(article, Pttrn, Lnk, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(150)).Replace("href=\"www.", "href=\"http://www."); + } + + public string ParseYoutube(string article) + { + if (string.IsNullOrEmpty(article)) return string.Empty; + + string pttrn = @"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)"; + string script = "
"; + + return Regex.Replace(article, pttrn, script, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(150)).Replace("https://