Is there a code editor that will allow copying of syntax highlighting to an Office Document for Windows? - ms-word

Is there a code editor that will allow copying of syntax highlighting to an Office Document for Windows?
I want to be able to copy code into a Word doc or EMail and preserve the Formatting when explaing code changes.
I will need support for multiple languages including C, C++, TCL, Javascript, Basic, and couple others.
The ability to include the line numbers for reference purposes would be a nice additional feature. I had one customer that required all code to be submitted with line numbers in a Word or PDF document.

I used Notepad++ in the past. It has a plug-in called NppExport and I think it has everything you need. The catch is that you have to write/open your source files with Notepad++, then export them to rtf, open the rtf and copy the pretty-formatted text to your doc file.
Here is the link to Notepad++ and to a good article to get you started with NppExport plugin.

Visual Studio (2010 Professional) "works fine" for copying code and formatting/coloring to MS Word (2010) and Outlook (2010)*. It supports at least C/C++/C#, and JavaScript code. It might support TCL/BASIC (it does support VB/VB.NET), but I do not use those languages. And, of course, VS is a full-blown IDE.
Visual Studio 2010 Express is free (as in beer). But as my company pays for my copy, I can only hope the copy'n'paste support works in Express as well ;-) In any case, it might be worth a try.
I am not sure if line-numbers can be exported via copy'n'paste, but I sort of doubt it. It's not a use-case I've run into.
Personally, I'd recommend doing the review via a SCM/code-review process and not manually, which just sounds like a nightmare. There are additional advantages of using tooling designed for this purpose including history management and talking about what really is, or could be (in relation to what was), and not a copy of what might have been.
Happy coding.
*After pasting into Microsoft Word, disable the "Add space after every paragraph" option to remove what appears to be blank lines from the pasted code.

Eclipse will do fine if you install the language support for all the wanted languages.

Related

How to paste text with links and formatting into VS Code like Obsidian?

If I copy the above text from Chrome and paste it into Obsidian, I get
People who code: we want your input. [Take the Survey](https://stackoverflow.com/dev-survey/start?utm_source=so-owned&utm_medium=announcement-banner&utm_campaign=dev-survey-2021)
[](https://stackoverflow.com/questions/ask# "dismiss")
But when I paste into VS Code or any other editor, I get
People who code: we want your input. Take the Survey
Video Reference: https://dsc.cloud/J/67968285.mov
How does Obsidian do it? How can I achieve the same in VS Code?
— — — — — — — — — — — — — — — — — — — — — — — — —
The Short Answer:
"        The VSCode editor does not support the feature you described, and VSCode will almost certainly never support any functionality that comes close to it. This is because of what VSCode is, and what VSCode does, which I will explain in detail below."
The Long Answer:
So VS-Code is a text-based editor, and its purpose is to be an environment that programmers can write their code in, therefore, people using VSCode are going to preform a long list of tasks which includes, but is not limited to:
interpret, compile, execute, debug, serve, share, save, write, read, document, and run code. Now here is the problem with adding the ability to paste arbitrary data types into VSCode. Having any type of data, other than standard text in a file that you plan on using to do one of the following (this is the very short list)...
compile,
execute,
debug,
interpret
parse,
serve,
...will cause a syntax error to be thrown.
When you can copy, and paste, text-formatting from an external source (like a webpage), there is an extremely high probability that some unwanted formatting data will get pasted into some program you've written, and the text's format-data will end up not rendering for what ever reason (theirs a million and 87 reasons why that would happen), and you end up getting syntax errors that you can't see, so you now have no idea where the error is, despite the error message saying line number 734 column 24. In a situation like this you will have an error message that makes no sense, and you will have to start deleting things to find the issue. all because it has text-formatting data intertwined with standard text-data, which you can't see. I hope I drew a clear enough picture for you.
Their are other tools called word processors that implement this feature. I constantly couple G-Docs with VSCode.
Crazy Enough, not all is lost
VSCode allows extensions to make custom editors. The Extension API used to create an editor (can be seen by clicking the link) lets developers build the UI using standard HTML, CSS, and JavaScript. This is enough for someone to write a Word Processor for VSCode, which surprisingly no one has done yet. When someone does create one, which I am almost certain that someone will eventually, in could support the feature your asking for.
For the record, the feature your describing is typically a word processor thing. VSCode allows you to install extensions such as PASTE, which copies and pastes other data types, however; when it is pasted into the editor, instead of rendering the data types like HTML, it just writes it in its text format. In other words, you might think your copying the page at first, but you will be disappointed once you paste to VSCode. I want to point out that Paste uses the GTK-3 Clipboards API, which means that if Paste were to be implemented in a word-processor, like word, or Google docs, those word processors would render the data the the Paste extension pasted into the word processor. In other words, it isn't the extension that is failing to render the Data (which as stated, can be done with the Paste Extension), but its VSCode that wonder render that data as HTML, but only accepts it as a standard text data type.
#W3Dojo
What you've copied can be considered "rich text", but VSCode treats everything in your clipboard as plain text.
So it's the same as pasting via "Ctrl+Shift+V" in other programs like Word or Google Docs. It will remove any formatting, links, color, font, bold/italic, etc.
Obsidian was built with formatting in mind - it closely follows the markdown specification, so it's natural that it will try to convert any rich text to markdown.
I'm not aware of a built-in VSCode setting that will allow you to paste rich text, but I've found 2 extensions that might do the trick:
Paste Special
Markdown Paste

Visual Studio Code Grammar files location

I'm using Visual Studio Code for development of PHP and would like to style the background color of the different embedded languages HTML/PHP/JavaScript differently, and to trigger the use of heredoc <<<sql .... sql to switch to SQL syntax. From what I can see from VSCode documentation, I need to edit the grammar files stored in storage.json, but for the life of me I cannot find where those files are. Can anyone point me in the right direction?
Sumirizing our comments, in order to modify the extension files, try to access the following folder:
./yourVSCodeFolder/extensions/resources/app/extensions
As you said, for those in windows, that folder is in:
%LocalAppData%\Programs\Microsoft VS Code\resources\app\extensions\php
There you will find a lot of folders that contains JSON files with the instructions of the custom formats and snippets that your editor uses.
For example: in mine, the /syntax/php.tmLanguage.json has all the instructions for how my php should look, and php/language-configuration.json has some parsing rules.
Find the files that allready has the rules that you are looking for, but it could be tricky because maybe you will need a prettyfier and to link or create new rules.
Also, if you didn't, check the Language Extensions Guide that VSCode provides.
Hope it was useful.
PD: As you also said:
VSCode already recognizes embedded SQL as long as the heredoc is in upper case <<<SQL .... SQL

Auto update changed paths like Dreamweaver, Possible in Sublime Text?

I recently started using Sublime Text 3, mostly for HTML and CSS and still learning the tricks.
In Dreamweaver, if I change a linked file/folder name or move it to different folder (within the project folder), it asks if all the html file containing those links should be updated and if confirmed it does updated the all the files in the project folder automatically, even the unopened files are updated! It saves a lot of time and errors.
This is the only feature I missed in Notepad++ when I used it for few projects.
Now, I am wondering if the above feature is there in Sublime Text (by default or with the help of some plug ins)?
I will greatly appreciate any helpful suggestion.
This feature is not present in Sublime by default, nor in any plugins of which I am aware, and although it is theoretically possible to write such a plugin it would be quite computationally intensive to have the feature "live". I find it much easier to keep CSS, JS, and markup in defined directories, and not move them around after creating them :)
You have to keep in mind that Notepad++ and Sublime Text are text editors, not IDEs, and so don't have all of the features of giant programs like Dreamweaver that are hundreds of times their size. Their primary purpose is editing and otherwise manipulating text, and ST at least (I'm not terribly familiar with N++) has a nice plugin API for writing functions to assist with that (such as inserting the path to a file), and people have even been able to write much more complex plugins to do things like linting and code intelligence, but things like keeping an eye on large groups of files and changing them all in response to certain events, or completely refactoring significant amounts of code, just isn't what it's designed for.

Read the word document conent without using Microsoft office

I am using word documents for the population of random mails. But to read the content, we are using MS Word. But the scripts are quite slow because of its auto-recovery feature.
My code is in powershell, is there any other alternative to read word docs? I tried to use wordpad but no success.
If they are docx files then they are an OpenXML format. Several solutions exists of reading docx files from code without requiring Office. See here and here. They are in C# but translating that to PowerShell should prove little problems. Or have a go with PowerTools for Open XML if you want to use PowerShell commands. Here is some more documentation on that subject.
If you mean you want to view them in their final format like a normal user would do, but without office, you can use this for example.
I have found the solution with the help of PowerTools for Open XML (Select-OpenXmlString -path $file_name).content.
To use powerTools on many machines will need Visual Studio to be installed on all machines which is not very feasible. It is available at: https://github.com/OfficeDev/Open-Xml-PowerTools
I have followed this screencast: http://www.youtube.com/watch?v=zU0utt3uga4.
And for other machines there is one small catch:
Copy the dlls by maintaining the folder structure
On the machine where you have built it. Copy the GAC C:\Windows\assembly\gac_msil\DocumentFormat.OpenXml and paste it to other machines where you want to use it.
Thanks Lars Truijens!!

Looking for a Document Comparer that can generate difference reports

I've been using an application called "WinMerge" lately for document comparisons, but one of the requirements of my teams script files (for auditing purposes) is that when we release a revision of a script we highlight the changes in red (RTF format I believe, it's through Lotus Notes) To that end, is there any software that can automatically highlight changes for me or is the best I'm going to get a list of differences and be expected to manually highlight all changes?
Assuming an HTML+CSS solution meets your needs, this article from Linux Journal shows a shell script that reads diff output and writes an HTML document with colored text highlighting the differences.
On Windows, it would probably work as-is under bash as provided in the MSYS environment from the MinGW folk or in bash from Cygwin. The script itself isn't too large, I would imagine it could be ported to Perl with only a moderate effort.
Since converting HTML to RTF turns out not to have a trivial solution that I've found, you might have better luck porting the script to directly output RTF.
If an HTML report is acceptable, Beyond Compare can generate a comparison report that highlights differences. You can use the built-in stylesheets or a custom internal one to style the differences in red (the default is a light red color already).
It doesn't seem to be able to generate RTF, but perhaps there is a simple conversion between html/css and rtf.