Skip to content

Commit 57ffe1b

Browse files
committed
initial commit
1 parent f00c93b commit 57ffe1b

File tree

8 files changed

+513
-0
lines changed

8 files changed

+513
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\CSHtml\CSHtml.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

CSHtml.Examples/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace CSHtml.Examples
4+
{
5+
internal class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
Console.WriteLine("Hello World!");
10+
}
11+
}
12+
}

CSHtml.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.2.32505.173
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSHtml", "CSHtml\CSHtml.csproj", "{333E0139-C853-464F-B888-E553E2B9CE45}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSHtml.Examples", "CSHtml.Examples\CSHtml.Examples.csproj", "{C988E54A-1430-40B4-938B-6AF680E74DE3}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{333E0139-C853-464F-B888-E553E2B9CE45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{333E0139-C853-464F-B888-E553E2B9CE45}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{333E0139-C853-464F-B888-E553E2B9CE45}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{333E0139-C853-464F-B888-E553E2B9CE45}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{C988E54A-1430-40B4-938B-6AF680E74DE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{C988E54A-1430-40B4-938B-6AF680E74DE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{C988E54A-1430-40B4-938B-6AF680E74DE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{C988E54A-1430-40B4-938B-6AF680E74DE3}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {DE9944F0-0AD5-419A-BA4E-1F1CD0AC7C87}
30+
EndGlobalSection
31+
EndGlobal

CSHtml/CSHtml.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net5.0;net48;netstandard2.1</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
</Project>

CSHtml/HtmlAttribute.cs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
namespace CSHtml
2+
{
3+
public enum HtmlAttribute
4+
{
5+
Accesskey,
6+
7+
Align,
8+
9+
Alt,
10+
11+
Background,
12+
13+
Bgcolor,
14+
15+
Border,
16+
17+
Bordercolor,
18+
19+
Cellpadding,
20+
21+
Cellspacing,
22+
23+
Checked,
24+
25+
Class,
26+
27+
Cols,
28+
29+
Colspan,
30+
31+
Disabled,
32+
33+
For,
34+
35+
Height,
36+
37+
Href,
38+
39+
Id,
40+
41+
Maxlength,
42+
43+
Multiple,
44+
45+
Name,
46+
47+
Nowrap,
48+
49+
Onchange,
50+
51+
Onclick,
52+
53+
ReadOnly,
54+
55+
Rows,
56+
57+
Rowspan,
58+
59+
Rules,
60+
61+
Selected,
62+
63+
Size,
64+
65+
Src,
66+
67+
Style,
68+
69+
Tabindex,
70+
71+
Target,
72+
73+
Title,
74+
75+
Type,
76+
77+
Valign,
78+
79+
Value,
80+
81+
Width,
82+
83+
Wrap,
84+
85+
Abbr,
86+
87+
AutoComplete,
88+
89+
Axis,
90+
91+
Content,
92+
93+
Coords,
94+
95+
DesignerRegion,
96+
97+
Dir,
98+
99+
Headers,
100+
101+
Longdesc,
102+
103+
Rel,
104+
105+
Scope,
106+
107+
Shape,
108+
109+
Usemap,
110+
111+
VCardName,
112+
113+
Data
114+
}
115+
}

CSHtml/HtmlBuilder.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace CSHtml
5+
{
6+
public class HtmlBuilder
7+
{
8+
private int _indentLevel = 0;
9+
10+
private string _tabString = "\t";
11+
12+
private TextWriter _writer;
13+
14+
public HtmlBuilder() : this(new StringWriter())
15+
{
16+
}
17+
18+
public HtmlBuilder(TextWriter writer)
19+
{
20+
this._writer = writer;
21+
}
22+
23+
public HtmlTagEntry AddTag(HtmlTag tag)
24+
{
25+
var htag = new HtmlTagEntry(this, tag.ToString());
26+
27+
this._indentLevel++;
28+
htag.OnDispose += this.onTagDisposed;
29+
30+
return htag;
31+
}
32+
33+
public HtmlTagEntry AddTag(HtmlTag tag, params (HtmlAttribute att, string value)[] arr)
34+
{
35+
var htag = new HtmlTagEntry(this, tag.ToString(), arr);
36+
37+
this._indentLevel++;
38+
htag.OnDispose += this.onTagDisposed;
39+
40+
return htag;
41+
}
42+
43+
public void Write(string line, bool tabs = true)
44+
{
45+
if (tabs)
46+
this.outputTabs();
47+
48+
this._writer.Write(line);
49+
}
50+
51+
public void WriteLine(string line)
52+
{
53+
this.outputTabs();
54+
this._writer.WriteLine(line);
55+
}
56+
57+
public override string ToString()
58+
{
59+
return this._writer.ToString();
60+
}
61+
62+
protected virtual void outputTabs()
63+
{
64+
for (int i = 0; i < this._indentLevel; i++)
65+
{
66+
this._writer.Write(this._tabString);
67+
}
68+
}
69+
70+
private void onTagDisposed(object sender, EventArgs e)
71+
{
72+
this._indentLevel--;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)