I have an html form that I want to force to convert whatever content it receives to plain text before sending it to my server (kind of similar to what happens in a simple text editor like OS-X TextEdit: where we can convert to PlainText whatever RichText formatted content). How do I do that? I don't really care where the user sees in the TextAreas, etc. I specifically want the text that arrives on the server to have been converted to PlainText.
It can be done using Jsoup.
Here is a sample code snippet:
public static String html2text(String html) {
return Jsoup.parse(html).text();
}
Related
We have an RPA on a site, to post a form. In the form we want to send HTML content with formatting. But the site is removing all the formatting, and is just showing html characters as is (like a text). But when we are copy pasting the content from tinymce editor (at our end) to the same site's form it is showing the content properly with formatting.
What needs to be done from my end while sending data to UiPath so that it puts the content in proper html format with formatting preserved?
I also tried sending html codes encoded by gson which is done by default. That also did not work.
This is when we are copy pasting the content -
And this is when we are sending data via uipath -
EDIT
This is what the uipath activity looks like (The description is being sent by an http api which uipath calls to get data) -
Thanks
Better use the Assign activity:
In the String variable website you simply save the HTML page. Now you can easily paste the variable anywhere. Also you don't need to paste the HTML in your editor via CTRL+V.
Just use the Type into activity:
I am taking HTML as input from a page using Tinymce(Rich Text editor), and saving input to SQL server , While retrieving the data form database and passing it to view ,all html tags and content are showing as plain text.
I am using asp.net core MVC.
This is where you would want to use Html.Raw()
Html.Raw() with render the HTML string you pass to it as markup on the page.
I can create my content fine using tinymce , it also uploads correctly to the database. here is an example of what stores in the database.
<p>Content goes in here</p>
When I choose to edit this it converts my p tags in the database to <p>
and then wraps the content in another set of p tags.
in source code of tinymce it looks like this
<p><p>this is a test message</p></p>
How do I stop this ?
as I just want it to render exactly as it is in the database.
I want to still store correct html tags in my database but I do not want tinymce to keep stripping/converting them.
Thanks in advance for your help.
Adam
Are you looking for somethink like that
tinymce.init({
...
entity_encoding : "raw"
});
tinymce encode the content before passing it to the server and hence the content is stored as: <p>This is text;/p> but the html tage are still passed like <p><p>This is text;/p></p>
While saving it to the database encode the values so that the html/xml tags are stored encoded. Like; Server.HtmlEncode(_propertyShopAdvertDetails.MarketingInformation);
and similarly while retrieving and displaying in the tinymce control the vaue needs to be decoded;
Server.HtmlDecode(_propertyShopAdvertDetails.MarketingInformation);
while retrieving the content and displaying it in the control, it decodes it and displays it correctly. Since it is displaying the content fine so I believe you have the right class on the control and used the correct mode for the plugin.
Now if you want to display the content in an HTML page and not inside tinymce control the you need to decode it. Something like: #Html.Raw(System.Web.HttpUtility.HtmlDecode(Model.PropertyFullDescription))
I have a rich text editor I'm working on where I need to parse and clean data from the clipboard when appropriate. Whenever the text being pasted contains HTML, I will clean it up and update the text field with the correct html.
However, when there is no html in the clipboard, there is no need for me to run the html cleaning tool.
My first thought was to use Regex and check for any html tag in there, but I'm not sure this is the best solution for this problem as it can cause more headaches in the long run with false positives, etc.
My question is, how can I detect some HTML in the clipboard?
Is there a an elegant way to solve this problem without having to resort to Regex?
may be one of these functions:
bool QDomDocument::setContent(...)
This function reads the XML document from the string text, returning true if the content was successfully parsed; otherwise returns false. Since text is already a Unicode string, no encoding detection is done
Addition for a clipboard's mixed data:
// get a html data from a junk
QString htmlText = cliboardString.section("</html>", -2, 0,QString::SectionIncludeTrailingSep)
.section("<html", 1,-1,String::SectionIncludeLeadingSep);
// check for a validness, correctness etc.
if( !htmlText.isEmpty() ) {
QDomDocument::setContent(htmlText,...
}
I have a form with a text field that users input text into. They can use multiple lines, put in bold text, underlined text, etc., but the text, when saved to SQL Server doesn't have any formatting saved, just the text is saved. What is the best way to save the text with the HTML so that when it gets viewed by another user and pulled up from Sql Server the HTML is saved and the formatting is saved?
Ex.
hello
Paul
This would be saved as
helloPaul
you can't see it but there are bold and carriage return html tags rapped around the text
When receiving data from the user, on the server side code, use HTML encode to safely store the data:
var inputData = Server.HtmlEncode("<strong>some data input from user</strong>"); //insert your user input data variable here
Then when displaying the data in your cshtml page, decode the data to display it as the user entered it:
HttpUtility.HtmlDecode(saveUserDataFromDatabaseVariable);
All this is assuming you have a rich text editor being plugged into the input field. CKEditor and TinyMCE are good ones.
You can use a text editor. Take a look at CKEditor. It's free and easy to use :)
Can you post some code and more details?
I have had good success with CKEditor. It is customizable, and its content can easily be saved via postback to a standard asp:TextBox.
It is possible that the editor you are using is not actually updating the input/textarea that you are using, it may be cloning the text and drawing the formatting in an overlay. You can use developer tools, or javascript, to verify this by checking the value property of the input or textarea element. If it is being saved via AJAX or javascript the code may be using the textContent or innerText properties instead of innerHTML.
I used the richtexteditor dll that's free online. it gave me a wiziwig box that the user can edit texxt in.