-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_text-zip.cshtml
57 lines (51 loc) · 1.35 KB
/
_text-zip.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@using Connect.Razor.Blade;
<div>
return to <a href="@Link.To()">overview</a>
</div>
<h1 class="sc-element">
Razor Blade Text.Zip
@Edit.Toolbar(Content)
</h1>
<div>
These demos show how to Zip (clean/compress) text properly, because Razor Blade handles a lot of issues you'll usually have cleaning up text.
</div>
@{
var samples = new string[] {
"This contains multi-spaces and \t\t\t tabs",
"This has \n \n line-breaks"
};
}
<h2>Example Text</h2>
Original which visually has unnecessary/problem characters:
<ul>
@foreach(var s in samples) {
<li>Raw: '@Html.Raw(ShowHiddenStuff(s))'</li>
}
</ul>
<h2>Correct and incorrect Character Counts</h2>
<table border="1">
<tr>
<th>Html output hiding problems</th>
<th>Whitespace output showing problems</th>
<th>Value.Length</th>
<th>Output using Text.Zip(...)</th>
<th>Text.Zip(...).Length</th>
</tr>
@foreach(var s in samples) {
<tr>
<td>@s </td>
<td style="white-space: pre-wrap;">@s</td>
<td>@s.Length </td>
<td style="white-space: pre-wrap;">@Text.Zip(s)</td>
<td>@Text.Zip(s).Length</td>
</tr>
}
</table>
@functions{
private string ShowHiddenStuff(string original) {
return original
.Replace("\n", "\\n")
.Replace(" ", " ")
.Replace("\t", "->");
}
}