Tools for generating syntax highlighted C# documentation (written in F#)
1. Generate a C# script (.csx) file and include some code, e.g.
using System;
Console.WriteLine("Hello World!");
2. Generate html documentation using the script file and the CSharp.Formatting
library.
C# Example
using CSharp.Formatting;
var data = System.IO.File.ReadAllText(@"ExampleScript.csx");
var html = HtmlGenerator.htmlEncodeSource(data);
System.IO.File.WriteAllText("test.html", html)
F# example
open CSharp.Formatting
let data = System.IO.File.ReadAllText """ExampleScript.csx"""
let html = HtmlGenerator.htmlEncodeSource data
System.IO.File.WriteAllText("test.html", html)
3. Review the result
<html>
<head>
<link rel="stylesheet" type="text/css" href="highlight.css"/>
</head>
<body>
<span class="keyword">using</span> <span class="other">System</span>;
<br/>
<br/>
<span class="classIdentifier" title="System.Console">Console</span>.<span class="methodIdentifier" title="System.Console.WriteLine(string)">WriteLine</span>(<span class="literal">"Hello World!"</span>);
</body>
</html>
Include documentation within your .csx
script file by using multiline comments of the form /***
and */
:
/***
This is documentation.
*/
Console.WriteLine("This is code.");
Standard multiline /*
, */
and single line comments //
will be higlighted like typical code comments in your IDE.
The formatting that the syntax highlighting produces is controlled by a style sheet called highlight.css
, here is an example:
.documentation {
font-family: Calibri;
font-size: 20px;
}
body {
background-color: white;
color: black;
font-family: Consolas,monaco,monospace;
font-size: 15px;
}
.block {
padding-left: 20px;
}
.keyword {
color : blue;
}
.literal {
color : OrangeRed;
}
.interfaceIdentifier {
color : Orange;
font-weight: bold;
}
.classIdentifier {
color : DodgerBlue;
font-weight: bold;
}
.structIdentifier {
color : DodgerBlue;
font-weight: bold;
}
.enumIdentifier {
color : yellow;
font-weight: bold;
}
.varIdentifier {
color : blue;
}
.attribIdentifier {
color : DarkViolet;
font-weight: bold;
}
.methodIdentifier {
}
.slComment {
color : green;
}