Skip to content
This is a port of ColorCode to .NET Standard. The original Html only formatter has been separated from the Logic, so now it can produce Syntax Highlighted code for any output. This Project can currently produce HTML, and Render to UWP RichTextBlocks.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ColorCode.Core Added Full debug symbols, updated MSBuild.Sdk.Extras. Oct 5, 2018
ColorCode.HTML -Added CSharp Number Scope. Dec 4, 2017
ColorCode.UWP Added Full debug symbols, updated MSBuild.Sdk.Extras. Oct 5, 2018
Tests Added Full debug symbols, updated MSBuild.Sdk.Extras. Oct 5, 2018
build Updated Build Scripts for bug being fixed. May 2, 2018
.gitattributes -Updated to .NET Standard 1.4. Nov 28, 2017
.gitignore -Updated .gitignore. Nov 28, 2017
ColorCode.sln -Renamed ColorCode to ColorCode.Core. Moved TextInsertion back to the… Nov 28, 2017
Directory.Build.props Updated Build Scripts for bug being fixed. May 2, 2018
appveyor.yml Added AppVeyor config. Dec 4, 2017
global.json
license.md -Updated to .NET Standard 1.4. Nov 28, 2017
readme.md Fixed Table issue May 13, 2018
version.json Updated version number. Oct 5, 2018

readme.md

ColorCode-Universal

This is a port of ColorCode to .NET Standard. The original Html only formatter has been separated from the Logic, so now it can produce Syntax Highlighted code for any output.

This Project can currently produce HTML, and Render to UWP RichTextBlocks.

Usage

HTML

To use ColorCode to create colorised HTML, ensure you have installed the ColorCode.HTML NuGet package, then you can use the following code:

var csharpstring = "public void Method()\n{\n}";
var formatter = new HtmlFormatter();
var html = formatter.GetHtmlString(csharpstring, Languages.CSharp);

This will create the formatting into the HTML, via inline styling. To use CSS to format the HTML instead, use the following:

var csharpstring = "public void Method()\n{\n}";
var formatter = new HtmlClassFormatter();
var html = formatter.GetHtmlString(csharpstring, Languages.CSharp);
var css = formatter.GetCSSString();

You will then have to manually reference the css, from the HTML head.

UWP

To use ColorCode to render colorized code to a RichTextBlock, then you can use the following code:

var csharpstring = "public void Method()\n{\n}";
var formatter = new RichTextBlockFormatter();
formatter.FormatRichTextBlock(csharpstring, Languages.CSharp, PresentationBlock);

Or you can append onto an existing InlineCollection, with the following code:

var paragraph = new Paragraph();
var csharpstring = "public void Method()\n{\n}";
var formatter = new RichTextBlockFormatter();
formatter.FormatInlines(csharpstring, Languages.CSharp, paragraph.Inlines);

Determining the Programming Language

To get the Programming Language manually, you can provide the identifier name, with the following code:

var language = ColorCode.Languages.FindById("java");

See LanguageId.cs for the list of available Languages to parse.

Packages

Package Description Supports
ColorCode.Core The Core Library, containing the Parser, and the classes to create your own formatter. .NET Standard 1.4
ColorCode.HTML The Library containing the HtmlFormatter, and the HtmlClassFormatter, for rendering Html from the Colorized Code. .NET Standard 1.4
ColorCode.UWP The Library containing the RichTextBlockFormatter, for rendering the Colorized Code to a RichTextBlock. Tested against 10.0.14393.0 and up.

Feedback and Requests

Please use GitHub issues for bug reports and feature requests.

Contributing

Want to help out and add some more parsing support, or add a new Formatter platform? Submit a PR!

You can’t perform that action at this time.