arilotta Posted December 17, 2020 Share Posted December 17, 2020 Hi all, I need to get the plain text from a UniHtmlMemo, without HTML tags. Using HtmlMemo.Text property returns text with HTML tags. The following works: unisession.addjs('alert('+HtmlMemo.jsname+'.getEditorBody().outerText);'); But I don't know if it is the best option. Also, how can I get the outerText value from Delphi (server side) code ? Thanks in advance Link to comment Share on other sites More sharing options...
andyhill Posted December 17, 2020 Share Posted December 17, 2020 Here is my function to strip HTML tags out of Text:- function TUniMainModule.StripHTML(S: String): String; var TagBegin, TagEnd, TagLength: Integer; MyStr: String; begin TagBegin:= Pos( '<', S); while (TagBegin > 0) do begin TagEnd:= Pos('>', S); TagLength:= TagEnd - TagBegin + 1; Delete(S, TagBegin, TagLength); TagBegin:= Pos( '<', S); end; MyStr:= S; if Pos(' ', MyStr, 1) > 0 then begin MyStr:= CRLF + MyStr; end; StringReplace(MyStr, #160, ' ', [rfReplaceAll, rfIgnoreCase]); MyStr:= Trim(MyStr); Result:= MyStr; end; Link to comment Share on other sites More sharing options...
arilotta Posted December 18, 2020 Author Share Posted December 18, 2020 Thank you andyhill, but accessing "getEditorBody().outerText" gives me back automatically CRLF characters. With the following HTML: <div><span style="color:black;font-family:'Arial';font-size:11.00pt;">line1</span></div> <div><span style="color:black;font-family:'Arial';font-size:11.00pt;">line2</span></div> your function does not return a CRLF between line1 and line2. Which is the correct way to access a ExtJS function/property from Delphi and obtain the result ? Link to comment Share on other sites More sharing options...
Sherzod Posted December 18, 2020 Share Posted December 18, 2020 14 minutes ago, arilotta said: <div><span style="color:black;font-family:'Arial';font-size:11.00pt;">line1</span></div> <div><span style="color:black;font-family:'Arial';font-size:11.00pt;">line2</span></div> Hello, Then you need to parse additionally I think. For example, before "StripHTML": UniMemo1.Text := StringReplace(UniMemo1.Text, '</div>', '</div>'#13#10, [rfReplaceAll]); Link to comment Share on other sites More sharing options...
arilotta Posted December 18, 2020 Author Share Posted December 18, 2020 Thank, but I think that accessing "getEditorBody().outerText" is the safest/quickest way. How can I achieve it ? This works: unisession.addjs('alert('+HtmlMemo.jsname+'.getEditorBody().outerText);'); I need to pass the getEditorBody().outerText value back to the UniGUI/Delphi environment. In general, I've learned that it is easy to call a JS procedure via JSCall. But how can I call a JS function and obtain a result from UniGUI ? Obviously, in a synchronous/blocking way, that is the Delphi statement should wait for the response and not proceed with the following line ? Sorry for bothering you Sherzod, but I think it could be useful for other users/tasks. Thank you Link to comment Share on other sites More sharing options...
Sherzod Posted December 18, 2020 Share Posted December 18, 2020 15 minutes ago, arilotta said: but I think that accessing "getEditorBody().outerText" is the safest/quickest way. Ok I will check. 15 minutes ago, arilotta said: I need to pass the getEditorBody().outerText value back to the UniGUI/Delphi environment. At what point? Link to comment Share on other sites More sharing options...
arilotta Posted December 18, 2020 Author Share Posted December 18, 2020 I need to have both the HTML version and the plain text version; the plain version will be used to compose a report and possibly to send an email. Thank you Link to comment Share on other sites More sharing options...
Sherzod Posted December 19, 2020 Share Posted December 19, 2020 23 hours ago, arilotta said: I need to have both the HTML version and the plain text version; the plain version will be used to compose a report Hello, Can you use client events for this? function change(sender, newValue, oldValue, eOpts) { ajaxRequest... } Link to comment Share on other sites More sharing options...
arilotta Posted January 12, 2021 Author Share Posted January 12, 2021 I'va managed to obtain the plain version in the following way, I'm sharing my solution because I thin it could be used also in other scenarions, when there is the need to obtain something from JS: FText: string; procedure TMyForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName='getHTMLtext' then FText:=Params.Values['t1']; end; ... ... UniSession.SendResponse('var t1='+HTMLData.JSName+'.getEditorBody().outerText; '+ ' ajaxRequest('+self.Name+', "getHTMLtext", ["t1="+t1]);'); UniSession.Synchronize; // processes request; fires AjaxEvent ShowMessageN(FText); ... ... Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now