Displaying code snippets in Sharepoint wiki

SharepointCode Formatting

Sharepoint 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:

Screenshot of Office 365 SharePoint insert ribbon

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:

  1. Copy code from IDE to new MS Word doc
  2. Highlight all in MS Word: Ctrl+A
  3. Copy again inside MS Word
  4. Switch to wiki page, Paste
  5. 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBoboTheCodeMonkeyView Question on Stackoverflow
Solution 1 - SharepointskyfootView Answer on Stackoverflow
Solution 2 - SharepointbranchgabrielView Answer on Stackoverflow
Solution 3 - SharepointchusteddeView Answer on Stackoverflow
Solution 4 - SharepointenglebartView Answer on Stackoverflow
Solution 5 - SharepointEric SabineView Answer on Stackoverflow
Solution 6 - SharepointShow34View Answer on Stackoverflow
Solution 7 - SharepointToddBView Answer on Stackoverflow
Solution 8 - SharepointJohn BabbView Answer on Stackoverflow
Solution 9 - Sharepointygy59View Answer on Stackoverflow
Solution 10 - SharepointMichael CoxonView Answer on Stackoverflow