• Stars
    star
    216
  • Rank 183,179 (Top 4 %)
  • Language
    C#
  • License
    Other
  • Created almost 7 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

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

More Repositories

1

WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
C#
5,887
star
2

dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
C#
3,007
star
3

Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
C#
2,203
star
4

MVVM-Samples

Sample repo for MVVM package
1,129
star
5

Lottie-Windows

Lottie-Windows is a library (and related tools) for rendering Lottie animations on Windows 10 and Windows 11.
C#
627
star
6

Windows

Collection of controls for WinUI 2, WinUI 3, and Uno Platform developers. Simplifies and demonstrates common developer tasks building experiences for Windows with .NET.
C#
538
star
7

Maui.Markup

The .NET MAUI Markup Community Toolkit is a community-created library that contains Fluent C# Extension Methods to easily create your User Interface in C#
C#
474
star
8

Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
C#
381
star
9

Labs-Windows

A safe space to collaborate and engineer solutions from the prototyping stage all the way through polished finalized component for the Windows Community Toolkit.
C#
324
star
10

Maui.NativeLibraryInterop

Maui.NativeLibraryInterop is a community-created library of binding samples to help .NET MAUI developers interop with native libraries more easily
C#
170
star
11

Graph-Controls

Set of Helpers and Controls for Windows development using the Microsoft Graph.
C#
155
star
12

Datasync

A collection of libraries that implement a client-server system used for synchronizing data from a cloud-based database.
C#
45
star
13

SceneLoader

A library for creating 3D Windows.UI.Composition.Scenes from glTF.
C#
36
star
14

Tooling-Windows-Submodule

Community Toolkit infrastructure for use as a submodule 'tooling' directory in other repositories.
C#
30
star
15

Sample-TabView-TearOff

Sample demonstrating using the TabView UWP control in the Windows Community Toolkit and Windows Template Studio's Multiple View feature to 'tear-off' tabs to create windows and drag them between windows.
C#
27
star
16

Labs-IntelligentAPIs

Intelligent APIs aim to make machine learning (ML) tasks easier for UWP developers to leverage in their applications without needing ML expertise or creating a new model.
C#
21
star
17

announcements

Subscribe to this repo to be notified of Announcements and changes in the Windows Community Toolkit
13
star
18

Sample-Graph-ContosoNotes

A simple note taking app infused with the power of Microsoft Graph and built with the Windows Community Toolkit!
C#
13
star
19

design-assets

Windows Community Toolkit design guide and templates
10
star
20

PWAWindowsHelpers

Helpers for Progressive Windows Apps running on Windows
JavaScript
9
star
21

WindowsCommunityToolkit-wiki

Wiki fork for main WindowsCommunityToolkit repo with project Documentation and Guidance
8
star
22

github-bot-uwp-toolkit

GitHub bot for the UWP Community Toolkit project to manage issues and Pull Requests
TypeScript
7
star
23

ToolkitLabs.dev

Repository for https://toolkitlabs.dev/ site
JavaScript
6
star
24

Labs-GazeControls

Set of user controls that can be reused in different applications with eye gaze input.
C#
6
star
25

Sample-Windows-CppWinRT

Sample which demonstrates using the Windows Community Toolkit within a C++/WinRT UWP application
C++
5
star
26

ReleaseNotesGenerator

dotnet core console app that generates release notes from pull requests for the UWP Community Toolkit
C#
4
star