Use CodeHighlighter directly in code

CodeHighlighter for ASP.NET Forum

Posted 16 years ago by Golo Roden
Version: 4.0.51
Avatar
Hi there,

I have got some questions regarding your CodeHighlighter component.

1. Do you have a working (!) example on how to use CodeHighlighter directly in code? In all examples I could find there is a method LoadFromXml on SyntaxLanguage type, but actually this method does not exist :-(

2. Do I have to deploy the .xml files, or is there a way to deploy only the .dll's?

Have a nice day,


Golo

Comments (4)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
1) You can create a CodeHighlighterEngine object and call its GenerateHtmlInline method.

Dynamic languages can be loaded from the DynamicSyntaxLanguage.LoadFromXml static method. It's on DynamicSyntaxLanguage, not SyntaxLanguage.

2) Yes unless you embed them in an assembly as a manifesst resource and load them from there.


Actipro Software Support

Posted 16 years ago by Golo Roden
Avatar
Hi,

thanks for your reply.

For the most languages I have gotten it to work now using the following code:
CodeHighlighterEngine engine = new CodeHighlighterEngine();
SyntaxLanguage language = DynamicSyntaxLanguage.LoadFromXml(@"ActiproSoftware.PHP.xml", 0);

string text = "using System;\n\npublic class Program\n{\n}";
text = engine.GenerateHtmlInline(Guid.NewGuid().ToString(), text, language);
Anyway, there are languages where this approach does not work, e.g. C#. When trying to load the data from the XML file I always get an exception telling me:

{"An error occurred while loading the DynamicSyntaxLanguage '{Unknown}':\r\nThe syntax language type 'CodeHighlighterTest.CSharpDynamicSyntaxLanguage, CodeHighlighterTest' could not be loaded. Please see the 'Troubleshooting' topic in the documentation for details on how to resolve this error.\r\nThe problem occurred near line 1, position 2\r\nin Unknown Stream."}

What is wrong with my code?

Thanks in advance,


Golo

[Modified at 04/11/2008 06:36 AM]
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Looks like the Troubleshooting topic is only in the SyntaxEditor control help. Here is the part that is is referring to:

If you copy one of our dynamic language definition samples from the sample project for use in your project, you may encounter this error message when you load the language in your application:

An error occurred while loading the DynamicSyntaxLanguage '{Unknown}': The syntax language type 'TestApplication.[LanguageName]SyntaxLanguage, TestApplication' could not be loaded. The problem occurred near line 1, position 2 in Unknown Stream

What is happening here is that the root SyntaxLanguage tag in the XML language definition is specifying which code-behind class to use for outlining and other features. The XML files are configured to work with our TestApplication assembly. However it's a quick change to make a copy of them work with your project.

These two topics describe how to use the SyntaxLanguage tag's SyntaxLanguageTypeName attribute and what value you need to set to get it working with your project:

[edit - Look at this topic in the CH documentation]: Dynamic Languages Guide / XML Definition Specification / SyntaxLanguage Tag


Actipro Software Support

Posted 16 years ago by Golo Roden
Avatar
Hi,

okay, thanks for your reply, I'll try to get it to work on the upcoming weekend ...

Cheerio,


Golo
The latest build of this product (v4.0.59) was released 13 years ago, which was after the last post in this thread.