Displaying code snippets in Sharepoint wiki
SharepointCode FormattingSharepoint Problem Overview
Is there a way to get SharePoint to display code snippets in a pre-formatted way?
Currently if you insert any code, it just looks exactly like the rest of the text. Anything would be better than nothing.
Sharepoint Solutions
Solution 1 - Sharepoint
I found hilite.me which produces html styled code which you can insert into a sharpoint wiki.
It supports a number of languages and styles and is an online app.
Solution 2 - Sharepoint
No because MOSS's wiki is just a new page with the word "wiki" attached to the link.
Solution 3 - Sharepoint
Even though this is an old question, I have yet another solution that possibly didn't exist at the time the question was asked:
You can create a GitHub Gist and use the embed code for the Gist on the SharePoint wiki page. This is especially useful if you are already using Gist, want to share the code snippet in multiple places aside from the wiki, and/or want to keep a history of the code snippet separate from the rest of the wiki page.
To use an embed code without the script tags being stripped, go to Insert > Embed Code in the ribbon when editing the page:
Solution 4 - Sharepoint
This solution assumes that you are using an IDE that already formats the code for you. Some of the other answers would be better if you have a raw text file.
While editing a Sharepoint Wiki page:
- Copy code from IDE to new MS Word doc
- Highlight all in MS Word: Ctrl+A
- Copy again inside MS Word
- Switch to wiki page, Paste
- Continue editing wiki or save
Works fine with Eclipse as IDE. Might be able to paste straight from VS to SharePoint.
If you have code snippets you will reuse in multiple pages, Use a similar copy/paste technique to save or upload htm files into a SharePoint document library and then insert a "Page Viewer Web Part" to view the htm inside a different page.
Solution 5 - Sharepoint
Not that I'm aware of if you're specifically using the Wiki feature. Your wiki entries are stored like rows in a table as far as I know. If you're not using the wiki you can use the syntax highlighter tool. It's all javascript. http://code.google.com/p/syntaxhighlighter/
Solution 6 - Sharepoint
For several weeks we are using Telerik Rad Editor
One of the tools is "Format Code Block" You may see it here : http://demos.telerik.com/aspnet-ajax/Editor/Examples/Default/DefaultCS.aspx
If you install the RadEditor for MOSS .. we will get this amazing tool in Wiki pages too.
Solution 7 - Sharepoint
So this is not a great answer but for us it was better then the default. You can write your wiki in a tool like Windows Live writer (WLW). WLW has an add in for a code formatter. If you write your wiki page via WLW with the code formatter you can then go to the Wiki page and select "edit HTML source." You can then copy from WLW to the wiki page and get good styling.
Solution 8 - Sharepoint
Best way I have found is to use tohtml.com
You can cut and paste your code into it and it will generate html that you can past into your sharepoint wiki
Solution 9 - Sharepoint
you can use prisimjs to show code snippets. When you add prisimjs and css you can use like this;
>
p { color: red }
if you want easier solution to use prisimjs, you can check this:
http://yasingokhanyuksel.blogspot.com.tr/2017/07/sharepoint-code-syntax-highlighting.html
Solution 10 - Sharepoint
If you want this for modern pages, there is the Source code content webpart from Qualitem.
https://spfxhub.com/packages/qualitem-source-code-content-web-part
Disclaimer: I am a co-developer.