Enforce ASCII encoding for a snippet of text / code in SharePoint site pages?

Anonymous
2016-08-25T04:16:27+00:00

We are a software company and would like some wiki system to document and share code snippets between personnel and teams. We tried MediaWiki and Confluence and they are really good and really suit our needs but require separate logins from what we already have with Office 365.

Ideally we would want only one login for all stuff, e.g. Office 365, and emails, and team tools, etc. So it's best if we could stick to SharePoint for this need.

However the issue with SharePoint site pages is that it keeps changing some of the bytes or characters of our code snippets into UTF8 encoding randomly, e.g. some /, some random letter or space, or something. When we copy and paste it in our system, or editor, or terminal window, they DONT' work. We had to manually type the snippets again.

This is really annoying. For example, on this page <Information masked by the moderator.>, one of the several Linux commands with paths have UTF8 encodings for:

  1. The 1st letter p
  2. The 1st and the 5th slash /

And when we use Insert > Embed Code, it's still the same issue only with different UTF8 encodings.

Is there any way we can enforce ASCII encoding for a snippet of content on SharePoint site pages?

Is there any recommended way to share and document computer program code on Office 365?

Microsoft 365 and Office | SharePoint | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2016-08-25T09:53:12+00:00

    Hi Datactory,

    To test, I tried adding the code to the web part, following are the steps:

    1. Navigate to your SharePoint site.
    2. Click Edit on the right.

                 

          3.Click Insert on the ribbon>Web Part>Media and Content>Script Editor (as shown below)>Add

              

          4.Click ‘Edit web Part’ as shown below.

         ![](https://learn-attachment.microsoft.com/api/attachments/75ec0353-7774-4eaf-a041-a3cb2853a2c4?platform=QnA)

         5.Once clicked on Edit Web Part, click the EDIT SNIPPET link to insert HTML/Script code.

         6.After you have inserted the appropriate code in the Embed dialog box, click Insert to save the HTML/Script.

        7.Click the Save button on the right corner of your site.

    You can try the above method, see if you get the desired result.

    If you still get any issues, please provide us with the following information:

    1. Can you provide us with sample code, which you entered, if possible? We will try it on our end.
    2. Please mention the steps you have taken to add the code.

    Moreover, we don’t have the access to the page you mentioned in the post, so can you provide us with the screenshot ?

    To protect the privacy, I have sent you a private message to write us the code. Please click hereto access your PM.

    Here are the articles and a post for reference:

    How to: Add a Web Part zone snippet in SharePoint 2013

    How to: Add a Security Trim snippet in SharePoint 2013

    Embedding html code in a SharePoint page 

     Note: Articles above are for SharePoint 2013 but the steps may be same for SharePoint online.

    Thanks,

    Neha

    0 comments No comments
  2. Anonymous
    2016-08-27T07:04:51+00:00

    Thanks for the help! Please see the screenshot attached. We have no Content Editor nor Script Editor in our Web Parts:

    How do we add them there?

    0 comments No comments
  3. Anonymous
    2016-08-29T05:20:05+00:00

    I tried the Script Editor but the issue persisted. When I copied the code from the Script Editor box, and pasted it, it still contained the invisible UTF8 characters that make the code inapplicable. Seems the Script Editor isn't UTF8-proof either.

    Content Editor seems a good idea in this that links an external file to the current site page. However as we would need quite some code snippets here and there per page, e.g. 10 or more, that are usually one or two-liners, it is really a chore to separately create external files for each of them, upload them and then link them as a Content Editor box.

    We would prefer an on-page solution.

    I tried to edit the site page that contained the code directly, deleting those invisible UTF8 characters with Backspace and Delete, and it worked. When I copied and pasted the code, they were properly working.

    How the invisible UTF8 characters came to be is now a mystery. Most of them are at beginning and end of lines.

    Now if we can get to know how those UTF8 characters came to be in the first place and prevent it, that would be it.

    I sent you the PM with the problematic code. Do you have any idea what those characters are and how they are produced while editing?

    0 comments No comments
  4. Anonymous
    2016-08-31T09:57:11+00:00

    Hi Datactory.com,

    The UTF8 characters you see is not just in SharePoint Online sites but it also appears in many other websites. It happens when you copy and paste the data from a site. The unwanted characters typically are formatting commands built into the originating program. A Unicode-based encoding such as UTF-8 can support many languages and can accommodate pages and forms in any mixture of those languages.

    So, to enforce ASCII encoding for an on-page solution, we suggest you contact the  SharePoint customization forum, as the experts there can help you with the customization of the master page.

    You can also try Content Editor or edit the site page that contained the code, as you mentioned.

    Thank you for your understanding.

    Regards,

    Neha

    0 comments No comments
  5. Anonymous
    2016-08-27T11:03:43+00:00

    Hi Datactory.com,

    As you wanted to enforce ASCII encoding for a snippet of content on SharePoint site pages, based on my research this may need some codes to be applied on the SharePoint page. E.g. adding <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> to the master page. In this scenario, we suggest you to turn on to SharePoint customization forum, which is specific channel for queries related to customization.

    As a workaround, you can also try uploading the code in a file with the correct encoding (ASCII) and use Content Script web part to display it. Below are the steps for your reference:

    To enable the Content Editor web part, follow the steps below to enable the Customer Scripting first:

    1. Go to SharePoint Admin Center >Click Settings.
    2. Scroll down to Custom Script, select ‘Allow users to run custom Script’ as shown in the following screenshot.

              

         3.Click OK.

    For reference: Turn scripting capabilities on or off

    Note:  It takes about 24 hours for the change to take effect.

    Then, try the following workaround to share code snippets:

    1. Save the code in ASCII format and upload it the document library.
    2. Now navigate to your SharePoint site.
    3. Click Edit on the right.
    4. Click Insert on the ribbon>Web Part>Media and Content>Content (as shown below)>Add

                  ![](https://learn-attachment.microsoft.com/api/attachments/dd187bd3-55eb-4263-a595-58fdac54dd97?platform=QnA)

             5. Click ‘Edit web Part’

             6. Content Editor window will appear, paste the URL of the uploaded document in the content link box as shown below.

                   ![](https://learn-attachment.microsoft.com/api/attachments/d2bf5d40-7470-4277-9503-46fa0ccd5d82?platform=QnA)

               7.Click OK

    Try the above work around and see if that works.

    Thanks,

    Neha

    0 comments No comments