C# syntax highlighter for blogging on BlogSpot - c#

I'm looking for a syntax highlighter cum code formatter for my blog on BlogSpot. I've tried several today, but the all want to include <style> tags, or reference a stylesheet. I'm looking for one that is ideal for segments of code, and includes styling inline. Any suggestions?

The project referenced above has moved:
http://alexgorbatchev.com/wiki/SyntaxHighlighter
Instructions for using it on Blogger:
mlawire.blogspot.com/2009/07/blogger-syntax-highlighting.html

You can always copy the extra few bytes of styling for, say, a Pygments highlighter (which really is quite excellent) into the <head> of your blog. You don't even need to install any software; just copy the HTML from the online service.

I've created a Free Online C# Syntax Highlighter that has exactly the ability you need - to inline the needed CSS styles. All you have to do is to select the "Inlined styles" check box, paste your C# code and click the Colorize button. You can find it on my blog.

Try this one: http://code.google.com/p/syntaxhighlighter/

I use SyntaxHighlighter Javascript Library. It's really easy to add and use.
here's more information on it that might help others out:
http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html

I had this exact problem.
I wrote an image formatter for Pygments (included in the core distribution).
Please don't hate me for such an abomination, but yes, it renders the highlighted code as a png or jpg or whatever you want. So it has no external dependencies etc.
pygmentize -f png -o mysource.png mysource.cs
I try to make sure that I always link a plain text version of the source for people copy-pasting.

Related

Visual Studio comments using images rather than text

I usually need to come back to old codes that I hardly remember after some weeks of work with other projects.
I try to write comments concisely, but still codes becomes messy.
Since I work mostly with computer geometry in Visual Studio C#, I was wondering if there is any "easy" way to add image comments rather than text?
I often place such 'documentation' in a project subfolder...
Then use the local FILE:// URI convention to link that image into my code comments or ever XML markup.. with the triple slash convention... which of course shows within intelligence
A comment can certainly link to an image (as a URL for example). But no, you can't embed an image as a comment. Code files are just text, not Word documents.
If the problem is that the code isn't clear and you're relying on comments to understand it, then the solution isn't to add more comments. The solution is to write code more clearly. Give variables semantically meaningful names, extract operations (every very small ones) into semantically meaningful methods. The code itself should tell you exactly what it's doing.

Bold or italic in C# or VB documentation comments?

Is there a way to use bold or italic inside documentation comments? Something like:
/// <summary>Cleanup method. This is <b>recommended</b> way of cleanup.</summary>
public void CleanAll();
The list of predefined tags does not contain such a feature, but do you know of some way of achieving emphasis/highlighting? Preferably, if it could be shown also in tooltips when hovering over the code.
We have <c> and <code> there, but they already have their semantics.
This feature is now available in Visual Studio 2019 version 16.3.0 (release notes).
You can use the <i> or <em> tags for italic.
You can use the <b>or <strong> tags for bold.
From the release notes, a variety of html tags seem to be supported, but the official documentation doesn't seem to be updated with this new feature just yet.
It looks like this: .
OP's note: This was the accepted answer before 2019 Visual Studio update after which I accepted the other answer. This one is still useful and valid for users without that update.
Not strictly, no. However, Sandcastle (a documentation generator that generates HTML from the documentation) supports to just use HTML in there, so you can use <em> and <strong> just fine if you build it with Sandcastle.
To put it another way: As Jamiec already notes, XML documentation comments are just XML. So you can put any valid XML in there; the compiler will happily write that into the documentation XML file. It all depends on the software that processes that file. Sandcastle just passes anything it doesn't know on as HTML, since that's its output format anyway.
Visual Studio will simply ignore them when displaying the help tooltip:
ReSharper in its Ctrl+Q view will show HTML tags as text which makes things a bit ugly:
Those are usually only of concern to you if you author a library to be used by others, though. But it also means that within the IDE no one can see your emphasis as intended.
I have found actually little need for emphasis when writing API documentation; oftentimes you can write a sentence differently or restructure to have important nodes in a separate paragraph near the end, to not need emphasis at all. Consistent language and phrasing also helps readers to pick up important notes once they're used to it.
Your code probably just was an example, but I think the summary needs emphasis least of all since it only notes – in a short sentence – what a type is or a method does. If anything, use it in the remarks and even then I'd carefully consider whether you actually need it.
There are other ways of adding emphasis:
- Upper case: some BOLD text // you are shouting, but they WILL read it
- First letter: some Bold text // less emphasis
- Asterisks: some **bold** text // 2 asterisks seem to work best
- Dashes: some --bold-- text // less emphasis
Plain text is old-school, but it can be very effective - and works long after the technology has changed.
An alternate way is to use a wiki markup-like style instead.
/// <summary>Cleanup method. This is *recommended* way of cleanup.</summary>
public void CleanAll();
Edit 1:
AFAIK Visual Studio doesn't understand wiki markup. I was just suggesting to use wiki markup as a convention. Your team would still see the raw (unformatted) wiki markup in the method's intellisense.
To add clarification to the accepted answer above ('This feature is now available in Visual Studio 2019 version 16.3.0' https://stackoverflow.com/a/58227889/17203657)
From the Release Notes (https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes-v16.3#net-productivity-163P1) 'There is now Quick Info style support for XML comments.'
Quick Info is when you hover over the method (it is NOT Intellisense), it DOES support Bold, Italic.
IntelliSense is what shows when you're adding arguments to the method, it does NOT support Bold, Italic.
As of VS 16.11.5 I've not found a way to add bolding or italics to the IntelliSense view.
Note: I do not have enough points to add this as a Comment.
I was trying to add a line break into the Intellisense display when I came across <see cref="YourReferenceHere"/> (see here), which inserts (according to the documentation) a clickable reference into the documentation. I have not figured out how to click on Intellisense tooltips, but it does provide a type-formatted/colored display which helps your reference to stand out (note that the reference must be available to Intellisense).
Side Note: I never did figure out how to do a single line break. Closest I can get is a double line break, using the <para/> tag...

.Net HTML Editor Control

I need to add in a WYSIWYG control into a .NET form. I found this one from SpiceLogic on several sites and was wondering if this is a decent library to use?
http://www.spicelogic.com/Products/NET-Win-HTML-Editor-Control-8/
If anyone has any additional input, I also would like to know of any other decent alternatives, both free and non-free.
Thanks in advance for any opinions on this!
EDIT Should have clarified this before, but this is a desktop application.
You can also try one of these strategies:
Use the RichTextBox control, which exposes a FlowDocument. Write a program that converts the FlowDocument to HTML. Since FlowDocs are much more constrained that HTML, this conversion might be pretty straightforward (sections -> div, paragraph -> p, styles -> css or style attributes, etc).
Use MSHTML and put it into edit mode. http://msdn.microsoft.com/en-us/library/aa753622(v=vs.85).aspx
You may want to try XStandard. I have used it in CMS web sites and it works great. You can also use it with desktop apps. There is a free "lite" version and a for=pay pro version. It creates XHTML markup and has lots of slick built-in functionality.
As a comparison, I have used Telerik RAD Editor and XStandard is much better (IMO). I have also tried other web-specific solutions like FCKEditor and TinyMCE and I prefer XStandard.
If your concern is to get XHTML all the time right from the beginning which should be published on the Web, then, I would say, "Yes", you can try that component from SpiceLogic, especially the version 5.x which was released very recently. It comes with many features like embedding images for an email client, Uploading local images to FTP, paste from MS Word, rich Dialogs for Tables, Images, Hyperlink, Symbols, Inline Spell Checker and Spell Checker dialogs, and more.
https://www.spicelogic.com/Products/NET-WinForms-HTML-Editor-Control-8
All Screenshots:
http://www.spicelogic.com/Products/NET-WinForms-HTML-Editor-Control-8/Screenshots
TinyMCE is a great way to achieve this. Here is a way to embed TinyMCE in Winform. I tested it and it works pretty well: https://github.com/Rocker93/winforms-html-editor
An other solution is CEFSharp. The integration is not easy but it's very well documented and it's the most powerful and free solution I have found.
At work we use telerik controls for this stuff:
http://www.telerik.com/products/aspnet-ajax/editor.aspx
its definitely not free though.

In Visual Studio, is there a quick way to generate these types of comment blocks?

If anyone knows the name for these types of comments, if one exists, please modify my question.
I frequently see comment blocks such as this:
/**********************************************
* Some Important Text Here
**********************************************/
Sometimes they can look like this:
/**********************************************
********* Some Important Text Here *******
**********************************************/
I've also seen them prettier than that.
They seem useful for noting sections of code, and important messages, such as license blocks. But, I feel like there *must* be a "lazy" way of doing this in Visual Studio, or at least an addon, because typing them manually is a pain.
Thanks!
P.S. If this feature or a point-and-click way to do it doesn't exist, then I know what VS plugin I'm writing next.
create a code snippet for them
You could perhaps look at GhostDoc, it is great for writing neat, clean, consistent style commenting in your code. It uses XML markup, and can later be exported for documentation.
If you want fixed-text blocks, then add a Code Snippet for each one you need.
If you want auto-generated documentation blocks for absolutely any code element, then you might like to try my addin, AtomineerUtils. (Similar to GhostDoc, but with significantly more features, a much better documentation generation engine, better formatting control (e.g. word wrapping of comments and documentation comments) and support for many more programming languages and documentation block styles).
You could create a toolbar macro which inserts that text at your cursor position when you click on the toolbar icon.

What's best way to format C# in WordPress?

Hey bloggers out there! I've created Wordpress blog that I am hosting myself, and I'm having the hardest time figuring out the best way to add C# snippets to my blog. What do you all use?
I'm currently using the "SyntaxHighlighter Evolved" plugin, and it works great for the most part - the only problem is that switching back to the Visual Editor removes all of the whitsepace padding. I've tried wrapping the [sourcecode] tags in <pre>'s, but then the formatter doesn't work correctly.
Any help would be much appreciated. I've spent about 10 hours trying to come up with a robust solution, and no luck.
Cheers!
See the blog post that I wrote on this exact question, which explains how to use SyntaxHighlighter and fix TinyMCE so that it doesn't mess up your white space or tags (you can either customize one of the tinymce files in Wordpress, or use a plugin to do it for you).
Use the WP-Syntax plugin. To use it, you wrap the code with a pre tag with a language attribute. Consolidates the effort.
If Client-Side (JavaScript) Syntax Highlighting is also an option, I can recommend google-code-prettify, which works quite well. Only a little Code escaping is needed to make it zero-friction for me as an author, as I detailed in a posting.
You can use Windows Live Writer to write post for your blog and use Steve Dunns live writer plugin.

Categories