Subject: SOL’N: Create Abstract frm Rich Text field & HTML Tag Stripper
Not sure if any of these are what you’re after, but if not, maybe other folks will find these useful.
- I haven’t tried this out – it’ll remove the HTML tags for you from a text
field – From: http://www.javascriptkit.com/script/script2/removehtml.shtml
- If you need to do this “on the fly” as the page is being submitted, try
something like this. We had to create a 150 character text-only version of an
RT field (JS not as consise as above for sure).
function getAbstract()
{
var form = document.forms[0];
var getAbs = form.Abstract.value;
if (getAbs == "" )
{
getAbs = form.BodyText.value;
//need to parse out html tags
var openPos;
var closePos;
var cleanStringPre;
var cleanStringPost;
//get started
openPos = getAbs.search(/</);
closePos = getAbs.search(/<*>/);
cleanStringPre = getAbs.slice(0, openPos);
cleanStringPost = getAbs.substr(closePos + 1);
//then loop through the string until all <> tags have been removed
while (cleanStringPost.match(/</))
{
openPos = cleanStringPost.search(/</);
closePos = cleanStringPost.search(/<*>/);
cleanStringPre = cleanStringPre + ' ' + cleanStringPost.slice(0,
openPos);
cleanStringPost = cleanStringPost.substr(closePos + 1);
}
//cleanStringPre may still have in it marking blank spaces, so
remove them while setting to getAbs var
getAbsFull = cleanStringPre.replace(/ /g, ' ')
if (getAbsFull.length > 150 )
{
getAbs = getAbsFull.slice(0, 151) + '...'
}
else
{
getAbs = getAbsFull
}
}
form.Abstract.value = getAbs;
}
Then in form submitDocument() function:
_getEditAppletData();
//write applet data to the plain text field, BodyText, by taking it from the
Domino field that stores the applet content
form.BodyText.value = form.Body.value;
getAbstract();
- Or, if you want to do this enmasse in a periodic LS agent, you can loop
through your documents …
If Not abstractFound Then
If doc.HasItem("BodyText") Then
'get body text into abstract, parse html, cut
at 150 characters
origBodyText = doc.BodyText(0)
interimText = HTMLTagStripper(origBodyText, " ")
parsedBodyText = Fulltrim( atReplaceSubstring(
atReplaceSubstring( interimText, " ", " " ), “ ”, " " ) )
If Len(parsedBodyText) >149
Then
abstractText = Left$(parsedBodyText,
-
& " …"
Else
abstractText = parsedBodyText
End If
Set item = doc.ReplaceItemValue("Abstract",
abstractText)
Call doc.Save(True, True)
Else
If doc.HasItem("Body") Then
'get body content into body text,
Set mime = doc.GetMIMEEntity("Body")
If Not( mime Is Nothing ) Then
doc.BodyText =
mime.ContentAsText
'get body text into abstract, parse html, cut
at 150 characters
origBodyText = doc.BodyText(0)
interimText =
HTMLTagStripper(origBodyText, " ")
parsedBodyText = Fulltrim(
atReplaceSubstring( atReplaceSubstring( interimText, " ", " " ), “ ”,
" " ) )
If Len(parsedBodyText) >149
Then
abstractText =
Left$(parsedBodyText, 150) & " …"
Else
abstractText =
parsedBodyText
End If
Set item =
doc.ReplaceItemValue(“Abstract”, abstractText)
Call doc.Save(True, True)
End If
End If
End If
End If ' ... if not abstractFound ...
Const HTML_PATTERN$ = “" & “[” & "<][>]*” ’ having trouble pasting the
string in here as a literal … you can chg it to 1 string in your code
Function HTMLTagStripper( source As String, separator As String ) As String
Dim newSource As String
Dim beforeTag As String
Dim afterTag As String
Dim startPos As Integer
Dim endPos As Integer
While source Like HTML_PATTERN$
startPos = Instr( source, "<" )
endPos = Instr( source, ">" )
If startPos > 1 Then
beforeTag = Mid$( source, 1, startPos - 1 )
Else
beforeTag = ""
End If
afterTag = Mid$( source, endPos + 1, Len( source ) )
newSource = Trim$( beforeTag ) + separator + Trim$( afterTag )
source = newSource
Wend
HTMLTagStripper = Trim$( source )
End Function