Project Description

Source Code Formatting Tool (For HTML compatible view) help in formatting the source code of different languages into html view.

There may be a situation when you publish/show your source code of different languages (like C#, C, C++, SQL/TSQL, etc. etc.) on web-pages. First question that comes to mind is, how to format the code and wrap your CSS around it to give a user friendly view. User friendly mean that just by looking on the content you can sense that this looks something known. Like an SQL code wrapped in blue, black and red color.

The difference is pretty clear between

select * from dbo.Employee where EmpName like 'A%'

and

select * from dbo.Employee where EmpName like 'A%'

The underline doc is based on Roslyn and Microsoft libraries published with SQL Server code parsers and compilers.

This project emerged from my need to show the source code on my web pages here. I am sharing this code so you can leverage the efforts.

Following components are available in Source Code Formatting Tool...

  • CodeFormatter (This is the main abstract of Source code formatting tool which contains the abstract "Format" method defining the signature of the method)
  • CSharpFormatter (This class override "Format" method and help format C# source code. This component generate the html/css combination of C# source code which looks like)Format C# Source Code
  • SqlFormatter (This class override "Format" method and format SQL/Transact-SQL source code. This component generate the html/css combination of SQL/T-SQL source code which looks like)Format C# Source Code
  • CssFormatter (This class override "Format" method and format CSS/Stylesheet content. The view of CSS/Stylesheet content will be something shown in the below image)Format CSS/Stylesheet Content
  • VisualBasicFormatter (This class override "Format" method and format Visual Basic Source Code. The view of Visual Basic source code would be similar to image shown below)Format Visual Basic Source Code
  • CFormatter (This class override "Format" method and format C/C++ Source Code to look like)Format C/C++ Source Code
  • HtmlFormatter (This class override "Format" method and format Html/DHTML content and make it look like)Format Html/DHtml Content

 

--------------------------------------------------------------------------------------------------------------------

31st Dec, 2013:

In this release of Source Code Formatting tool, I have added the formatter for Html source code (HtmlFormatter). This will help you view the html source code formatted as HTML look in the development environment. The HtmlFormatter is based on the WebBrowser object. HtmlFormatter iterates through the complete HTML content using HTML elements. It uses recursion to iterate through all the child nodes and collectively forms the output embeded with CSS around HTML tags.

--------------------------------------------------------------------------------------------------------------------

Recently added new sample project for MVC and jQuery to support "Format Source Code". Using jQuery code calling MVC Action to format the source code available inside teavchSourceCodeFormatter css class.

--------------------------------------------------------------------------------------------------------------------

Following blogpost can help understand how the source code works...

Source Code format to HTML - SQL/TSQL
Source Code format to HTML - CSS
Source Code format to HTML - C#

Hope this help :)...

Teavch

Last edited Jan 1, 2014 at 6:11 PM by teavch, version 13