Text To Html In Sharepoint Using Javascript
I have a summary single-line text column in SharePoint 2007 that is a truncation of a multi-line text column. Going through the complicated process to get there, it turns into tex
Solution 1:
How about using Christophe's techniques to output HTML using a calculated column.
Specifically he has written javascript that will turn the encoded HTML (which you've now got) into HTML.
Add the following into a Content Editor Web Part (CEWP) on the same page.
<scripttype="text/javascript">/*
Text to HTML Lite - version 2.1.1
Questions and comments: Christophe@PathToSharePoint.com
*/functionTextToHTML(NodeSet, HTMLregexp) {
varCellContent = "";
var i=0;
while (i < NodeSet.length)
{
try
{
CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
if (HTMLregexp.test(CellContent))
{ NodeSet[i].innerHTML = CellContent; }
}
catch(err)
{}
i=i+1;
}
}
// Calendar viewsvar regexpA = newRegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*");
TextToHTML(document.getElementsByTagName("a"),regexpA);
// List viewsvar regexpTD = newRegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"),regexpTD);
</script>
Solution 2:
I have modified the TextToHTML code from below link, source is PathToSharePoint.com and I have added an event listener which works on SharePoint 2016 successfully in IE compatiblity mode which runs as IE10 and Chrome latest version: Text to Html conversion in Sharepoint 2010
<scripttype="text/javascript">/*
Text to HTML Lite - version 2.1.1
Questions and comments: Christophe@PathToSharePoint.com
*/document.addEventListener("DOMContentLoaded", function() {
functionTextToHTML(NodeSet, HTMLregexp) {
varCellContent = "";
var i = 0;
while (i < NodeSet.length) {
try {
CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
if (HTMLregexp.test(CellContent)) {NodeSet[i].innerHTML = CellContent;}
}
catch (err) {}
i = i + 1;
}
}
// Calendar viewsvar regexpA = newRegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*");
TextToHTML(document.getElementsByTagName("a"), regexpA);
// List viewsvar regexpTD = newRegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"), regexpTD);
// This function is call continuesly every 100ms until the length of the main field changes// after which the convert text to HTML is executed.var postElemLength = 0;
functionPostConvertToHtml() {
if (postElemLength == document.getElementsByTagName("TD").length) {
setTimeout(PostConvertToHtml, 100);
}
else {
var regexpTD = newRegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"), regexpTD);
}
}
// Grouped list viewsExpGroupRenderData = (function(old) {
returnfunction(htmlToRender, groupName, isLoaded) {
var result = old(htmlToRender, groupName, isLoaded);
var regexpTD = newRegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"), regexpTD);
};
})(ExpGroupRenderData);
// Preview pane viewsif (typeof (showpreview1) == "function") {
showpreview1 = (function(old) {
returnfunction(o) {
var result = old(o);
var regexpTD = newRegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"), regexpTD);
};
})(showpreview1);
}
});
</script>
Post a Comment for "Text To Html In Sharepoint Using Javascript"