Displaying code snippets in Sharepoint wiki
Asked Answered
R

10

54

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.

Romalda answered 29/12, 2008 at 17:55 Comment(0)
D
60

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.

Desman answered 26/1, 2011 at 16:20 Comment(2)
The HTML can be used from Editing Tools > Format Text > HTML > Edit HTML SourceTsaritsyn
Just to clarify, take the HTML you get from hilite.me , while editing your wikidoc, go to the 'Insert' tab , 'Embed', and paste it there.Fia
C
5

No because MOSS's wiki is just a new page with the word "wiki" attached to the link.

Counterscarp answered 31/12, 2008 at 21:27 Comment(1)
not totally true. it supports some subset of wiki syntax like. [[Dogs]] : A link to a page named Dogs in the same folder. [[Animals/Dogs]] : A link to a page named Dogs in a subfolder called Animals. [[List:Announcements/Welcome]] : A link to the item called Welcome in the Announcements list on this site.Oddment
M
5

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

Milagrosmilam answered 17/3, 2016 at 15:52 Comment(2)
Would you elaborate how you got this to work? Since embedding that code uses a <script> tag, it seems either the HTML editor doesn't like it and removes it or there is a security issue about running other sites' scripts.Payer
@Payer I edited my answer to show where you can add an embed code in the web editor.Milagrosmilam
I
3

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.

Ibadan answered 25/7, 2014 at 19:33 Comment(1)
For those who try the attempt above: user Internet Explorer! Chrome 46 converts all colors (from Eclipse) and almost all colors (from IntelliJ IDEA) to grey during the copy-paste from Word to SharePoint.Tsaritsyn
J
1

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/

Jackofalltrades answered 31/12, 2008 at 21:40 Comment(0)
B
1

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.

Bernardinebernardo answered 8/1, 2009 at 22:51 Comment(0)
V
1

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

Veto answered 24/2, 2015 at 9:26 Comment(0)
O
0

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.

Ovoviviparous answered 28/3, 2013 at 22:12 Comment(0)
H
0

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

Hanafee answered 26/7, 2017 at 7:44 Comment(0)
T
-1

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.

Thiouracil answered 10/3, 2020 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.