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.
Перейти к файлу
Dongbo Wang 34878acb21 Add the language parser for JSON 2023-07-13 09:17:36 -07:00
ColorCode.Core Add the language parser for JSON 2023-07-13 09:17:36 -07:00
ColorCode.HTML Multi-target .NET Standard 1.4 and 2.0 2022-08-24 16:26:43 -07:00
ColorCode.UWP Update Min Version targetted for UWP and WinAppSDK, up WindowsAppSDK version 2022-08-24 15:12:46 -07:00
ColorCode.WinUI Update Min Version targetted for UWP and WinAppSDK, up WindowsAppSDK version 2022-08-24 15:12:46 -07:00
Tests Change license to MIT 2022-08-24 14:40:17 -07:00
build Fixing build errors with CI (#31) 2022-10-27 09:04:16 -07:00
.editorconfig Fixing build errors with CI (#31) 2022-10-27 09:04:16 -07:00
.gitattributes
.gitignore Added WinUI3 version. 2021-03-30 14:18:35 -07:00
ColorCode.sln Fixing build errors with CI (#31) 2022-10-27 09:04:16 -07:00
ColorCode.snk
Directory.Build.props Downgrade the WindowsAppSDK version back to 1.0.4 2022-09-07 13:57:30 -07:00
Directory.Build.targets Updated to WAS 1.0.0 GA. 2021-11-16 11:13:05 -08:00
azure-pipelines.yml Get ahead on build version numbers for a change finally 2022-10-27 13:55:53 -07:00
global.json Updated to VS 2022. 2021-11-17 12:35:53 -08:00
license.md Change license to MIT 2022-08-24 14:40:17 -07:00
readme.md Add WindowsAppSDK mention to readme, fix linting 2022-08-24 15:12:46 -07:00
version.json Get ahead on build version numbers for a change finally 2022-10-27 13:55:53 -07:00

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 and WindowsAppSDK 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!

License

MIT