Skip to content
Advertisement

How to display T-SQL in html with proper formatting?

I’m sure this has to be a duplicate, but I guess my searching skills aren’t on point today.

I want to display SQL code in html (like in blogs and such), and I want it to be formatted like you would see it in Management Studio or any other editor that supports SQL. I’ve found a nuget package that does this for WinForms, but I can’t seem to find anything that does it for the web.

Other languages like C# would be nice as well, but at the moment only SQL is required. Ideally a javascript or jquery plugin that does it on the fly would be nice. But it would also be fine if I had to use something to transform the text ahead of time into html. Preferably not through a website where I have to copy/paste every snippet I want to do, but ideally I would be able to have access to use the code so I can automatically process a lot of snippets at once.

Advertisement

Answer

I have been using Poor man’s TSQLFormatter for SQL Server formatting needs. I have used their NOTEPAD++ plugin and online formatter. They are very good.

You can use their different libraries for your needs. You can find the different libraries in the download section

Advertisement