Giter Club home page Giter Club logo

azchohfi / colorcode-universal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from communitytoolkit/colorcode-universal

0.0 2.0 0.0 2.29 MB

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.

License: Microsoft Public License

C# 97.64% PowerShell 2.34% Batchfile 0.02%

colorcode-universal's Introduction

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!

colorcode-universal's People

Contributors

bashirsouid-ms avatar csainty avatar daanx avatar half-ogre avatar williamabradley avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.