Skip to content

Commit

Permalink
adding support for tags: h1, h2, h3, h4, h5, h6, p.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maniceraf committed Jun 14, 2024
1 parent 18bf135 commit 56936a5
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 42 deletions.
20 changes: 17 additions & 3 deletions EasyHtmlToolkit.Test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EasyHtmlToolkit.Models;
using EasyHtmlToolkit.Enums;
using EasyHtmlToolkit.Models;
using EasyHtmlToolkit.Models.Elements;

namespace EasyHtmlToolkit.Test
Expand All @@ -7,7 +8,20 @@ public class Program
{
static void Main(string[] args)
{
Example1();
var h1 = new H1Tag("Happy niu year");

h1.SetStyle("color", "blue");
h1.SetStyle("color", "red");

Console.WriteLine(h1.Styles);

Check failure on line 16 in EasyHtmlToolkit.Test/Program.cs

View workflow job for this annotation

GitHub Actions / build

'H1Tag' does not contain a definition for 'Styles' and no accessible extension method 'Styles' accepting a first argument of type 'H1Tag' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 16 in EasyHtmlToolkit.Test/Program.cs

View workflow job for this annotation

GitHub Actions / build

'H1Tag' does not contain a definition for 'Styles' and no accessible extension method 'Styles' accepting a first argument of type 'H1Tag' could be found (are you missing a using directive or an assembly reference?)

var doc = new HtmlDocument();

doc.Body.AddChildren(h1);

h1.SetStyle("color", "yellow");

doc.SaveToDownloadsFolder();
}

public static void Example1()
Expand Down Expand Up @@ -66,7 +80,7 @@ public static void Example2()
var document = new HtmlDocument();

// Create a button element
var button = new HtmlElement("button");
var button = new HtmlElement(ETag.button);
button.InnerText = "Click Me";

// Set the accesskey attribute for the button (e.g., Alt + B)
Expand Down
43 changes: 43 additions & 0 deletions EasyHtmlToolkit/Enums/ETag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.ComponentModel;

namespace EasyHtmlToolkit.Enums
{
public enum ETag
{
[Description("script")]
script = 0,

[Description("style")]
style = 1,

[Description("head")]
head = 2,

[Description("body")]
body = 3,

[Description("h1")]
h1 = 4,

[Description("h2")]
h2 = 5,

[Description("h3")]
h3 = 6,

[Description("h4")]
h4 = 7,

[Description("h5")]
h5 = 8,

[Description("h6")]
h6 = 9,

[Description("p")]
p = 10,

[Description("button")]
button = 11,
}
}
9 changes: 5 additions & 4 deletions EasyHtmlToolkit/HtmlDocument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EasyHtmlToolkit.Models;
using EasyHtmlToolkit.Enums;
using EasyHtmlToolkit.Models;
using System.Text;

namespace EasyHtmlToolkit
Expand All @@ -16,8 +17,8 @@ public class HtmlDocument

public HtmlDocument()
{
Head = new HtmlElement("head");
Body = new HtmlElement("body");
Head = new HtmlElement(ETag.head);
Body = new HtmlElement(ETag.body);
}

#endregion
Expand All @@ -26,7 +27,7 @@ public HtmlDocument()

public void AddStyle(string css)
{
var styleElement = new HtmlElement("style");
var styleElement = new HtmlElement(ETag.style);
styleElement.InnerText = css;
Head.AddChildren(styleElement);
}
Expand Down
24 changes: 24 additions & 0 deletions EasyHtmlToolkit/Models/Elements/H1Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
/// <summary>
/// This is h1 tag.
/// </summary>
public class H1Tag : HtmlElement
{
/// <summary>
///
/// </summary>
public H1Tag() : base(ETag.h1) { }

/// <summary>
///
/// </summary>
/// <param name="value"></param>
public H1Tag(string value) : base(ETag.h1)
{
InnerText = value;
}
}
}
14 changes: 14 additions & 0 deletions EasyHtmlToolkit/Models/Elements/H2Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class H2Tag : HtmlElement
{
public H2Tag() : base(ETag.h2) { }

public H2Tag(string value) : base(ETag.h2)
{
InnerText = value;
}
}
}
14 changes: 14 additions & 0 deletions EasyHtmlToolkit/Models/Elements/H3Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class H3Tag : HtmlElement
{
public H3Tag() : base(ETag.h3) { }

public H3Tag(string value) : base(ETag.h3)
{
InnerText = value;
}
}
}
14 changes: 14 additions & 0 deletions EasyHtmlToolkit/Models/Elements/H4Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class H4Tag : HtmlElement
{
public H4Tag() : base(ETag.h4) { }

public H4Tag(string value) : base(ETag.h4)
{
InnerText = value;
}
}
}
14 changes: 14 additions & 0 deletions EasyHtmlToolkit/Models/Elements/H5Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class H5Tag : HtmlElement
{
public H5Tag() : base(ETag.h5) { }

public H5Tag(string value) : base(ETag.h5)
{
InnerText = value;
}
}
}
14 changes: 14 additions & 0 deletions EasyHtmlToolkit/Models/Elements/H6Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class H6Tag : HtmlElement
{
public H6Tag() : base(ETag.h6) { }

public H6Tag(string value) : base(ETag.h6)
{
InnerText = value;
}
}
}
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlAnchor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlAnchor : HtmlElement
{
public HtmlAnchor() : base("a") { }
public HtmlAnchor() : base(ETag.h1) { }

public void SetHref(string href)
{
Expand Down
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlCell.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlCell : HtmlElement
{
public HtmlCell() : base("td") { }
public HtmlCell() : base(ETag.h1) { }
}
}
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlDiv.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlDiv : HtmlElement
{
public HtmlDiv() : base("div") { }
public HtmlDiv() : base(ETag.h1) { }
}
}
8 changes: 5 additions & 3 deletions EasyHtmlToolkit/Models/Elements/HtmlRow.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlRow : HtmlElement
{
public HtmlRow() : base("tr") { }
public HtmlRow() : base(ETag.h1) { }

public void AddCell(HtmlCell cell)
{
AddChild(cell);
AddChildren(cell);
}
}
}
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlSpan.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlSpan : HtmlElement
{
public HtmlSpan() : base("span") { }
public HtmlSpan() : base(ETag.h1) { }
}
}
7 changes: 4 additions & 3 deletions EasyHtmlToolkit/Models/Elements/HtmlTable.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using EasyHtmlToolkit.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlTable : HtmlElement
{
public HtmlTable() : base("table")
public HtmlTable() : base(ETag.h1)
{
}

public void AddRow(HtmlRow row)
{
AddChild(row);
AddChildren(row);
}

public void AddRowFromData(params string[] cellData)
Expand Down
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlTableBody.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlTableBody : HtmlElement
{
public HtmlTableBody() : base("tbody")
public HtmlTableBody() : base(ETag.h1)
{
}
}
Expand Down
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlTableFooter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlTableFooter : HtmlElement
{
public HtmlTableFooter() : base("tfooter")
public HtmlTableFooter() : base(ETag.h1)
{
}
}
Expand Down
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlTableHeader.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlTableHeader : HtmlElement
{
public HtmlTableHeader() : base("thead")
public HtmlTableHeader() : base(ETag.h1)
{
}
}
Expand Down
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlTd.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlTd : HtmlElement
{
public HtmlTd(string value) : base("th")
public HtmlTd(string value) : base(ETag.h1)
{
InnerText = value;
}
Expand Down
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlTh.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlTh : HtmlElement
{
public HtmlTh(string value) : base("th")
public HtmlTh(string value) : base(ETag.h1)
{
InnerText = value;
}
Expand Down
6 changes: 4 additions & 2 deletions EasyHtmlToolkit/Models/Elements/HtmlTr.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EasyHtmlToolkit.Models.Elements
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class HtmlTr : HtmlElement
{
public HtmlTr() : base("tr")
public HtmlTr() : base(ETag.h1)
{
}
}
Expand Down
12 changes: 12 additions & 0 deletions EasyHtmlToolkit/Models/Elements/PTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using EasyHtmlToolkit.Enums;

namespace EasyHtmlToolkit.Models.Elements
{
public class PTag : HtmlElement
{
public PTag(string value) : base(ETag.p)
{
InnerText = value;
}
}
}
Loading

0 comments on commit 56936a5

Please sign in to comment.