具有语法突出显示的Eclipse复制代码

时间:2022-05-16 22:57:35

I'm writing a document of programming guidelines for my developers team. I use MS Word. We work with Eclipse CDT (C++). I need to copy-paste C++ code with syntax highlighting from Eclipse to Word. I've tried Notepad++ and it can export text with syntax highlighting, but it's highlighting is limited to basic syntax (it doesn't know about defined class, enum etc...). Eclipse syntax highlighting is very powerful and I wish to export directly from Eclipse to Word using it's syntax highlighting.

我正在为我的开发团队编写一份编程指南文档。我用MS Word。我们使用Eclipse CDT(C ++)。我需要使用从Eclipse到Word的语法高亮复制粘贴C ++代码。我已经尝试过Notepad ++,它可以导出带有语法高亮的文本,但它的突出显示仅限于基本语法(它不知道已定义的类,枚举等...)。 Eclipse语法高亮非常强大,我希望使用它的语法高亮直接从Eclipse导出到Word。

Is there any Eclipse plugin that achieve this purpose? Or some trick to do it (without taking a screen snapshot)?

是否有任何Eclipse插件可以实现此目的?或者做一些技巧(没有拍摄屏幕快照)?

4 个解决方案

#1


18  

When you copy the code to word document, you can choose the option "keep source formatting" and the highlighting will be the same as the one in eclipse.

将代码复制到word文档时,可以选择“保持源格式”选项,突出显示将与eclipse中的突出显示相同。

EDIT:

As mentioned in the comments below, this won't work on folded code, so you can right click on the line numbers and select Folding > Expand All

如下面的评论中所述,这不适用于折叠代码,因此您可以右键单击行号并选择折叠>全部展开

EDIT 2: Also mentioned in the comments, as of eclipse oxygen, the code is automatically copied with syntax highlighting

编辑2:在评论中也提到,从eclipse氧气开始,代码会自动复制并带有语法高亮显示

#2


3  

When I copy from Eclipse straight to PowerPoint some of the formatting is messed up. Bold and color seems to "keep going". But if I copy from Eclipse to Word -- and then from Word to PowerPoint (with the keep source formatting CNTRL-K) -- the formatting is correct. I recently upgraded Eclipse to Mars and Office to 2013. I still have to go through Word first.

当我从Eclipse直接复制到PowerPoint时,一些格式被搞砸了。大胆和色彩似乎“继续前进”。但是,如果我从Eclipse复制到Word - 然后从Word复制到PowerPoint(使用保留源格式CNTRL-K) - 格式化是正确的。我最近将Eclipse升级到Mars和Office升级到2013.我仍然需要先通过Word。

#3


0  

I was trying it too and for some reason not every compile unit would keep the formating.

我也在尝试它,由于某种原因,不是每个编译单元都会保持格式化。

After a while I've seen that you also won't get the formating kept if there are parts of the code hidden, so for the ones that cannot make it work with the answers above, just make sure that there are no "+" signs on the left of your code (mine were where the imports at the beggining).

过了一会儿,我已经看到如果隐藏了部分代码,你也不会保持格式化,所以对于那些无法使其与上述答案一起工作的那些,只要确保没有“+”你的代码左边的标志(我的是在开始时的进口)。

#4


0  

Copying of formatting is supported since version 3.2

从版本3.2开始支持复制格式

Note that everything is copied: highlighting of spelling errors, marked variables/types/etc and underscoring of warnings/errors.

请注意,所有内容都被复制:突出显示拼写错误,标记变量/类型/等,并强调警告/错误。

To avoid that, turn off spell checking, "Mark Occurrences" and "Report problems as you type" respectively.

为避免这种情况,请分别关闭拼写检查,“标记出现次数”和“在键入时报告问题”。

#1


18  

When you copy the code to word document, you can choose the option "keep source formatting" and the highlighting will be the same as the one in eclipse.

将代码复制到word文档时,可以选择“保持源格式”选项,突出显示将与eclipse中的突出显示相同。

EDIT:

As mentioned in the comments below, this won't work on folded code, so you can right click on the line numbers and select Folding > Expand All

如下面的评论中所述,这不适用于折叠代码,因此您可以右键单击行号并选择折叠>全部展开

EDIT 2: Also mentioned in the comments, as of eclipse oxygen, the code is automatically copied with syntax highlighting

编辑2:在评论中也提到,从eclipse氧气开始,代码会自动复制并带有语法高亮显示

#2


3  

When I copy from Eclipse straight to PowerPoint some of the formatting is messed up. Bold and color seems to "keep going". But if I copy from Eclipse to Word -- and then from Word to PowerPoint (with the keep source formatting CNTRL-K) -- the formatting is correct. I recently upgraded Eclipse to Mars and Office to 2013. I still have to go through Word first.

当我从Eclipse直接复制到PowerPoint时,一些格式被搞砸了。大胆和色彩似乎“继续前进”。但是,如果我从Eclipse复制到Word - 然后从Word复制到PowerPoint(使用保留源格式CNTRL-K) - 格式化是正确的。我最近将Eclipse升级到Mars和Office升级到2013.我仍然需要先通过Word。

#3


0  

I was trying it too and for some reason not every compile unit would keep the formating.

我也在尝试它,由于某种原因,不是每个编译单元都会保持格式化。

After a while I've seen that you also won't get the formating kept if there are parts of the code hidden, so for the ones that cannot make it work with the answers above, just make sure that there are no "+" signs on the left of your code (mine were where the imports at the beggining).

过了一会儿,我已经看到如果隐藏了部分代码,你也不会保持格式化,所以对于那些无法使其与上述答案一起工作的那些,只要确保没有“+”你的代码左边的标志(我的是在开始时的进口)。

#4


0  

Copying of formatting is supported since version 3.2

从版本3.2开始支持复制格式

Note that everything is copied: highlighting of spelling errors, marked variables/types/etc and underscoring of warnings/errors.

请注意,所有内容都被复制:突出显示拼写错误,标记变量/类型/等,并强调警告/错误。

To avoid that, turn off spell checking, "Mark Occurrences" and "Report problems as you type" respectively.

为避免这种情况,请分别关闭拼写检查,“标记出现次数”和“在键入时报告问题”。