Publishing Field encoding extra “?” questionmark charecters (actually acsii 8203 zero width space )

Assume that you have created a new article page then Typed some string in Page Content.
After Selected this content and make it bold.
Then clicked the
HTML Source.-> In html source we see following looks no unusual charecter in it .
<p><strong>sharepoint</strong></p>

But if we copy this string tsource to another program for example notepad++ We can see “?” <p><strong>sharepoint</strong>?</p> …. or if you run following powershell:

$site = get-spsite http://contoso
$web = $site.OpenWeb()
$list = $web.Lists[“Pages”]
$page = $list.GetItemById(<ItemId>)
$page[“Page Content”]

Result is same :<p><strong>sharepoint</strong>?</p>

+It is happen only when the first page created and saved.
+Issue happen when we reach data with OM or copy paste outside of the SharePoint to another advanced text editor program.

Similar :http://social.msdn.microsoft.com/Forums/sharepoint/en-US/23804eed-8f00-4b07-bc63-7662311a35a4/why-does-sharepoint-put-in-character-code-8203-in-a-richtext-field?forum=sharepointdevelopment

You may face this issue Both SharePoint 2010 and Sharepoint 2013

Unfortunately this is by design . The “Page Content” field or Publishing HTML Fields uses RTE (Rich text editor). RTE sometimes adds zero width space (&#8203) as a workaround to ensure cursor range selection is correct in some browsers. When viewing “HTML Source”, browser HTML doesn’t render zero width space character. But after copying the string out,like notepad++ and powershell renders it as an unknown character (?). It is rare condition and not happen always and depends many various factors But if you have facing this
For a resolution, you may need use some custom codes for remove that charecter in related string.
String.Replace(  ((char)8203).ToString(), “” );

Advertisement

SharePoint Word Count with Rich Text Editor

This could only be achieved via custom development and is not possible by using SharePoint’s out
of the box features or setup options  this following blog where a word count is achieved with JavaScript:
https://www.nothingbutsharepoint.com/sites/eusp/Pages/add-character-or-word-count-to-sharepoint-multi-line-plain-text-field-and-restrict-input-length.aspx

But there is also an exception , it is only working for a Input element.

Rich Text Box are different than normal text box

<TD vAlign=top width=190 noWrap>
<H3><NOBR>RichText</NOBR> </H3></TD>
<TD vAlign=top RteRedirect=”[Control Chain]_TextField_inplacerte”><!– FieldName=”RichText”
FieldInternalName=”RichText”
FieldType=”SPFieldNote”
–><SPAN>
<DIV>
<DIV style=”DISPLAY: none” id=[Control Chain]_TextField_inplacerte_label>Rich text editor</DIV>
<DIV aria-haspopup=true style=”MIN-HEIGHT: 84px” id=[Control Chain]_TextField_inplacerte role=textbox aria-labelledby=[Control Chain]_TextField_inplacerte_label contentEditable=true InputFieldId=”[Control Chain]_TextField_spSave” UseInlineStyle=”True” aria-autocomplete=”both” aria-multiline=”true”>
<P>​</P></DIV>
<DIV style=”CLEAR: both”></DIV></DIV>
<SPAN dir=ltr><INPUT id= [Control Chain]_TextField_spSave name=[Control Chain]TextField_spSave type=hidden> </SPAN></SPAN></TD>

Text Area :
<TR><TD vAlign=top width=190 noWrap>
<H3><NOBR>RichText</NOBR> </H3></TD>
<TD vAlign=top><!– FieldName=”RichText”
FieldInternalName=”RichText”
FieldType=”SPFieldNote”
<SPAN><TEXTAREA id=”[Control_Chain]_TextField title=RichText cols=20 rows=6 name=””></TEXTAREA>
<BR></SPAN></TD></TR>

SharePoint 2010 has using also div based RTE so javascript codes based on above artilce can be adjust like that;

<script src="<your jquery path and version>/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('div[role*="textbox"]').bind('keyup blur',function(e){
 var thisLength = $(this).text().length;
if(true && thisLength>0){
thisLength = $(this).text().split(/[' '|\n]/).length;
}

if(true && 200>0){

if(thisLength>(200-5)){
$("#myCustomCounter_").css({'background-color':'#FF0000','font-weight':'bold','color':'white'});
}else if(thisLength>(200-10)){
$("#myCustomCounter_").css({'background-color':'#FF6600','font-weight':'bold','color':'white'});
}else{
$("#myCustomCounter_").css({'background-color':'transparent','font-weight':'normal','color':'black'});
}

}

if(200>0){
if(true){
while(thisLength>200){
currVal = $(this).text();
$(this).val(currVal.substring(0,currVal.lastIndexOf(' ')));
thisLength--;
}
}else{
if(thisLength>200){
currVal = $(this).text();
$(this).val(currVal.substring(0,200));
}
}
thisLength = (200-thisLength<0)?0:200-thisLength;
}

$("#myCustomCounter_").html("Remaining words asda: "+thisLength);
}).parents('td:first').append("<span id='myCustomCounter_' style='padding:2;'></span>").find('input[name*="TextField_spSave"]');

​</script>