Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax-highlighting textbox for Winforms, ASP.NET, WPF

I'm looking for a syntax-highlighting Textbox component, preferably free, with source, and capable of being used in Winforms, ASP.NET and WPF alike. Also, it should support not just display, but also editing contents.

I've discovered the excellent, FREE ActiPro SyntaxHighlighter for ASP.NET but that's unfortunately ONLY for ASP.NET and it only displays text in syntax highlighted manner, it has no editing capabilities.....

I also know of the ICSharp Text Editor component that's part of SharpDevelop but that's then a standalone, but Winforms only, solution.

Does anyone know of a component that has a core to handle the syntax-highlighting (configurable, so I can use it for C# code, XML and HTML files, and more), and that has three "skins" for Winforms, ASP.NET and WPF? I'd really prefer to have ONE core that does the heavy lifting, and three UIs on top sharing that core code....

Any pointers and hints are welcome!

like image 312
marc_s Avatar asked Feb 16 '09 14:02

marc_s


1 Answers

Perhaps consider CodeMirror items for the web. Obviously this won't work for WPF as you'd asked, but it'll work for any web framework - Webforms, ASP.NET MVC, plain HTML, PHP and others.

CodeMirror is a JavaScript library that can be used to create a relatively pleasant editor interface for code-like content ― computer programs, HTML markup, and similar. If a parser has been written for the language you are editing (see below for a list of supported languages), the code will be coloured, and the editor will help you with indentation.

Parsers for :

  • JavaScript
  • XML/HTML
  • CSS
  • HTML mixed-mode
  • SPARQL
  • HTML+PHP mixed-mode
  • Python
  • Lua
  • Ruby
  • SQL
  • PLSQL
  • diff
  • Groovy
  • C#
  • Scheme
  • Java
  • XQuery
  • OmetaJS
  • Freemarker

Implementation:

<textarea  rows="30" cols="120" id="someCode" >
    //some comments
    var foo = "bar";
</textarea>

You include 2 .js references, and then this bit of JavaScript replaces your textarea elements with new syntax highlighted elements.

<script type="text/javascript">
    var textarea = document.getElementById('someCode');
    var editor = new MirrorFrame(CodeMirror.replace(textarea), {
        height: "350px",
        content: textarea.value,
        parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
        stylesheet: "css/jscolors.css",
        path: "js/",
        autoMatchParens: true
    });
</script>

The CodeMirror manual helps.

Also consider the WikiPedia entry for Comparison of JavaScript-based source code editors

like image 124
p.campbell Avatar answered Sep 22 '22 08:09

p.campbell