JeringTech / Javascript.NodeJS

Invoke Javascript in NodeJS, from C#
Other
455 stars 43 forks source link

Does it support highlight.js #126

Closed LittleNewton closed 2 years ago

LittleNewton commented 2 years ago

Hi~

I am using C# to develop a Microsoft Word plugin. I want to highlight some source code to be written in MS Word.

Once I tried to make a parser, but there were so many different languages to be supported. That is too hard. So I turned to a famous JavaScript lib which was called highlight.js.

However, another problem occurred. I have to run js in the .Net environment. Firstly, I tried the Microsoft JScript .Net library. After I learned how to use it, I found that it doesn't support ECMA6 or the newer version. So I try to use Jering's lib.

I wonder whether this project will satisfy my need. I want Node.JS to run the highlight.js and give me the rendered HTML to paste into the Word document. Thanks!

My Project: https://github.com/LittleNewton/Equation_and_Codebox Highlight.js: https://highlightjs.org/

JeremyTCD commented 2 years ago

Hi, yes it can do what you need.

Some time back I wrote example projects invoking Highlight.js and Prism using this library: HighlightJS, Prism.

Let me know if you have any issues!

LittleNewton commented 2 years ago

Thank you for your helpful response!

I am learning your Jering.Web.SyntaxHighlighters.HighlightJS cases. It looks very awesome.

I have another question. I don't know how to render the HTML/CSS file to a richtext object which can be pasted into a Microsoft Word document. I consider using the traditional webBrowser class, but it only supports the Internet Explorer browser.

LittleNewton commented 2 years ago

image

Wonderful! By using Jering.Web.SyntaxHighlighters.HighlightJS, I could call Highlight.JS to generate HTML. But there is a Node.JS black Window on the side. Is there any method to make it not show?

JeremyTCD commented 2 years ago

Hmm I'll update Jering.Web.SyntaxHighlighters.HighlightJS to use the lastest Jering.Javascript.NodeJS package later today. I think that might remove the Node.js window.

LittleNewton commented 2 years ago

After trying to upgrade the Jering.Web.SyntaxHighlighters.HighlightJS NuGet package, I successfully upgrade Jering.Javascript.NodeJS from v4.3.0 to v6.2.0. However, my project can be built successfully after the upgrading, but it cannot call the highlight.js program as I wish. The run time error said like the following:

System.IO.FileLoadException: '未能加载文件或程序集“Jering.Javascript.NodeJS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)'

It seems that Visual Studio 2022 cannot load the program collection Jering.Javascript.NodeJS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. So I had to downgrade the NuGet package to the old version.

My project's target framework: .NET Framework 4.6.1

JeremyTCD commented 2 years ago

Hey I'm updating it here: Jering.Web.SyntaxHighlighters.HighlightJS pull request. Should be publishing a new Jering.Web.SyntaxHighlighters.HighlightJS package by today. If you're in a hurry you can clone the pull request branch.

JeremyTCD commented 2 years ago

Published Jering.Web.SyntaxHighlighters.HighlightJS 3.4.0!

LittleNewton commented 2 years ago

Published Jering.Web.SyntaxHighlighters.HighlightJS 3.4.0!

Thanks! The new release works nice in my project.