Skip to content

Instantly share code, notes, and snippets.

@jbasinger
Last active January 2, 2021 18:02
Show Gist options
  • Save jbasinger/991ea0d63661430fe94cd293055001f9 to your computer and use it in GitHub Desktop.
Save jbasinger/991ea0d63661430fe94cd293055001f9 to your computer and use it in GitHub Desktop.
Blazor Code Snippet Components
<pre class="code"><code class="@Language">
@ChildContent
</code></pre>
@code {
[Inject] private IJSRuntime _js { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public string Language { get; set; } = "csharp";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await _js.InvokeVoidAsync("highlightSnippet");
}
}
<body>
<app>Loading...</app>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/languages/csharp.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/languages/css.min.js"></script>
<script>
window.highlightSnippet = function(){
document.querySelectorAll('pre code').forEach((el)=>{
hljs.highlightBlock(el);
});
}
</script>
<script src="_framework/blazor.webassembly.js"></script>
</body>
<CodeSnippet>
public class PersonModel
{
public int Id { get; set; }
[Display(Name="First Name")]
public string Name { get; set; }
public string City { get; set; }
public string State { get; set; }
[BlazinHeaderFormat("{0:C}")]
public int Salary { get; set; }
[BlazinHeaderIgnore]
public string ThisColumnWontEvenShowUp { get; set; }
}
</CodeSnippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment