Skip to content

Commit

Permalink
#2 Added HTML Encode/Decode
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHedley committed Dec 12, 2020
1 parent 9654e7c commit 30d98e9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Utility-Blazor/Pages/HTML.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@using System.IO;
@using System.Net;

@page "/html"

<h1>HTML</h1>

<div class="container">
<div class="row">
<textarea id="decoded" class="form-control" rows="5" @bind="decoded"></textarea>
</div>
<div class="row">
<button id="btnEncode" name="btnEncode" class="btn btn-success float-right"
@onclick="Encode">
Encode
</button>
</div>
<div class="row">
<textarea id="encoded" class="form-control" rows="5" @bind="encoded"></textarea>
</div>
<div class="row">
<button id="btnDecode" name="btnDecode" class="btn btn-success float-right"
@onclick="Decode">
Decode
</button>
</div>
<div class="row">
<div>@((MarkupString)encoded)</div>
</div>
</div>

@code {

string decoded;
string encoded;

protected override async Task OnInitializedAsync()
{
decoded = "&lt;html&gt;&lt;body&gt;&lt;h1&gt;Hello&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;";
encoded = string.Empty;
}

private void Encode()
{
var writer = new StringWriter();
WebUtility.HtmlDecode(decoded, writer);
encoded = writer.ToString();
}

private void Decode()
{
decoded = WebUtility.HtmlEncode(encoded);
}

}
5 changes: 5 additions & 0 deletions src/Utility-Blazor/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<span class="oi oi-code" aria-hidden="true"></span> Hidden Char Finder
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="html">
<span class="oi oi-browser" aria-hidden="true"></span> HTML
</NavLink>
</li>
</ul>
</div>

Expand Down

0 comments on commit 30d98e9

Please sign in to comment.