C++ MS Word 文档中的语法突出显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2556862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:54:15  来源:igfitidea点击:

Syntax highlighting in MS Word document

c++cms-wordsyntax-highlighting

提问by Arun

I want to insert some C/C++ source code into a Microsoft Word document. I have no problem in copying the code from source file and pasting into Word. I can do fixed-width. But, in Word, I see the code in black-and-white format; I loose the syntax highlighting as I get in the source code editor (for me, gvim). So, my question is, is there any way to do syntax highlighting of C/C++ source code in MS Word?

我想在 Microsoft Word 文档中插入一些 C/C++ 源代码。我从源文件中复制代码并粘贴到 Word 中没有问题。我可以做固定宽度。但是,在 Word 中,我看到的是黑白格式的代码;当我进入源代码编辑器(对我来说,gvim)时,我松开了语法突出显示。所以,我的问题是,有没有办法在 MS Word 中对 C/C++ 源代码进行语法高亮显示?

回答by Ethan Liu

I found Notepad++also can copy the code as .rtf file. Plugin/NppExport/Copy RTF to Clipboard, Then you can paste them into word with highlight and layout.

我发现Notepad++也可以将代码复制为 .rtf 文件。 Plugin/NppExport/Copy RTF to Clipboard,然后您可以将它们粘贴到带有突出显示和布局的 word 中。

回答by Lukasz Czerwinski

I've found a tool similar to this found by darlinton, but having several different styles of colouring: http://tohtml.com/. I hope it would help.

我找到了一个类似于 darlinton 找到的工具,但有几种不同的着色风格:http://tohtml.com/ 。我希望它会有所帮助。

回答by Vitali Climenco

You can leverage the syntax highlighter that is in use at StackOverflow. I mean the text area where you add the content to be posted to the site :)

您可以利用StackOverflow中使用的语法荧光笔。我的意思是您添加要发布到网站的内容的文本区域:)

But for a more robust and configurable solution you could check out the syntax highlighter developed by Alex Gorbatchov (link). But well, installing it requires some knowledge of HTML and CSS. So, if I needed a quick solution to format my output, I would opt for planet.ca, as darlintonand ArunSaha.

但是对于更健壮和可配置的解决方案,您可以查看由 Alex Gorbatchov 开发的语法高亮器(链接)。但是,安装它需要一些 HTML 和 CSS 知识。所以,如果我需要一个快速的解决方案来格式化我的输出,我会选择planet.ca,因为达林顿ArunSaha

回答by RichieHindle

If you don't mind using a different editor for this job, you could load your code into SciTE, use the Edit / Copy as RTFcommand, and then paste into Word.

如果您不介意为此工作使用不同的编辑器,您可以将您的代码加载到SciTE 中,使用Edit / Copy as RTF命令,然后粘贴到 Word 中。

回答by Shiroko

If you have Eclipse CDT or Visual around they do it automatically for you when you paste code to Word (Or similiar). I assume it's not best solution for a gvim guy, but still. Just so you'll know.

如果您有 Eclipse CDT 或 Visual,当您将代码粘贴到 Word(或类似的)时,它们会自动为您执行此操作。我认为这不是 gvim 人的最佳解决方案,但仍然如此。只是为了让你知道。

回答by Arun

After some more searching, I also found Highlight 2.9. But that requires (a) installing an application, and (b) [subjective] aesthetically I like the output of planetb.ca's output (the answer provided by darlinton)

经过一番搜索,我还找到了Highlight 2.9。但这需要 (a) 安装应用程序,并且 (b) [主观] 从美学上讲我喜欢Planetb.ca的输出(由 darlinton 提供的答案)

回答by Jér?me Pouiller

Under Linux, you can use the popular highlightpackage. It can output RTF file. You can copy-paste the result in Word or LibreOffice.

在 Linux 下,您可以使用流行的highlight包。它可以输出RTF文件。您可以在 Word 或 LibreOffice 中复制粘贴结果。