0

This might be really very simple, I have a list view with multiple Rich Text fields, I want to remove HTML formatting from those field in a specific view and return them as Plain text.

I would like to do it without using RegEx. I am sure there must be any simple ways. Any suggestions?

1
  • Is this considered a duplicate? Similar questions can be found on stack overflow, since the underlying question here is how to strip HTML formatting from text.
    – wjervis
    May 15, 2014 at 16:31

1 Answer 1

0

It was simpler then i thought. Implemented JSLink for the same...

(function () {

// Create object that have the context information about the field that we want to change it output render 
var viewContext = {};
viewContext.Templates = {};

viewContext.Templates.Fields = {
    "Field":{"View": renderPlainText}       
};

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(viewContext);})(); 

My render function looks like below:-

function renderPlainText(ctx) {
var value = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
value = value.replace(/<(?:.|\n)*?>/gm, '');
return "<div>" + value + "</div>"; }
2
  • Your function uses regular expressions, which you said you did not want.
    – yandr
    May 16, 2014 at 6:35
  • sorry for the confusion, all the other ways i found was implemented using SharePoint object model where we SPListItem class had a method for returning the value as plain text, thought of going ahead with whatever i can find fast :) May 16, 2014 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.