How to use Syntax highlighter in ASP.NET MVC
By FoxLearn 2/18/2024 1:37:43 AM 308
Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. It’s used in thousands of websites, including some of those you visit daily.
For more details, you can visit website https://prismjs.com/
To install Prism you should download prism.css and prism.js, then add to your website as below
<!DOCTYPE html> <html> <head> <link href="themes/prism.css" rel="stylesheet" /> </head> <body> <script src="prism.js"></script> </body> </html>
You can add a simple css code as below. In this forum, i'm using Prism to highlight the syntax
The second way, i would like to introduce to you is highlight.js. This is useful for syntax highlighting for the web site. You can download it directly at https://highlightjs.org/
<link rel="stylesheet" href="/path/to/styles/default.css"> <script src="/path/to/highlight.pack.js"></script> <script>hljs.initHighlightingOnLoad();</script>
Add the snippet above to your website to initialize the highlighter syntax. This will find and highlight the code inside of <pre><code> tags. It will automatically detect the language. If automatic detection doesn’t work for you, you can specify the language in the class attribute.
<pre><code class="html">...</code></pre>
- How to use CORS in ASP.NET Core
- How to Send Emails in ASP.NET Core
- How to Run Background Tasks in ASP.NET Core with Hosted Services
- Implementing Scheduled Background Tasks in ASP.NET Core with IHostedService
- Creating an Web API in ASP.NET Core
- 8 Essential Tips to Protect Your ASP.NET Core Application from Cyber Threats
- 10 Common Mistakes ASP.NET Developers Should Avoid
- How to Upload Files Using C# ASP.NET FileUpload Control