I have a QTextEdit that has several lines (Name, Age, Height).
self.textbox = QTextEdit(self)
self.textbox.setPlainText('Name:\n Age: \nHeight: \n')
self.enteredText = self.textbox.toPlainText()
I want to put this information into a Jinja2 HTML template so it shows in the following way:
Personal data:
Name: (whatever the user wrote after "name")
Age: (whatever the user wrote after "age")
Height: (whatever the user wrote after "height")
I'm having issues with linebreaks, I'm not sure how to process my QTextEdit so that I also get the linebreaks in HTML. I tried self.enteredText.splitlines(True) but HTML does not understand \n as linebreak and my text is all in one line.
I know almost nothing about jinja html templates, but you could try joining the lines together using br tags:
lines = '<br/>'.join(self.enteredText.splitlines()).
Related
i have a string stored in database which contains line break, it should looks like following when displaying on page:
abc
def
hkg
now i need to add this string to an email dialog as email content and its format should be:
my thymeleaf text template to generate email content looks like:
Test: [# th:each="g : ${gList}"]
Description:
[(${g.descr})]
However, after i added the template content to a textarea, it is:
that is there is no indent from line 2, this is not what i want.
how can i get the format like following for one string which contains multiple lines?
Test:
Description:
abc
def
hkg
The html code to show the email content in dialog is :
<div class="row">
<label class="col-2 text-right">Content:</label>
<textarea id="emailContent" class="col-9" v-model="email.content" >
</textarea>
</div>
another question is : what if this string is long but no line break, it only has spaces between words. in this case, it still display the rest of this string from line 2 without indent.
The string stored in the database is abc\ndef\nhkg therefore when you print it out you are getting:
Test:\n
....Description:\n
........abc\n
def\n
hkg
Since this is plain text and you don't have any of the formatting capabilities of html, you're going to have to modify the string itself. Basically, you need to replace your newlines \n with 8 spaces and a new line. You want the string to look like:
abc\n........def\n........hkg
As for what that looks like in Thymeleaf. Kind of ugly, but I think this should work for you:
Test: [# th:each="g : ${gList}" th:with="newline=${T(System).getProperty('line.separator')}"]
Description:
[(${#strings.replace(g.descr, newline, newline + ' ')})]
I have a few thousand large documents saved locally, where they are all saved as HTML files. Each document is about 300 pages long, and has some sections that have titles in bold letters. My goal is to do a text search in these files, and when I find the given phrase, extract the whole section that contains this phrase. My idea was to parse the html text so that it becomes a list of paragraphs, find the location of the phrase, and then extract everything from the bold letters (title of this section) just prior to bold letters just after (title of the next section).
I tried in a number of different ways, but none of them does what I want. the following was promising:
myhtmlfile = "I:/myfolder/myfile.html"
myhtmltxt2 = htmlTreeParse(myhtmlfile, useInternal = TRUE)
But while I can display the object "myhtmltxt2" and it looks like html with tags (which is what I need so that I can look for "<b>" ), it is an external pointer. So then I am not able to the command below, because grep does not work on pointers.
test2<-grep("myphrase",myhtmltxt2,ignore.case = T)
Alternatively, I did this:
doc.text = unlist(xpathApply(myhtmltxt2, '//p', xmlValue))
test3<-grep("myphrase",doc.text,ignore.case = T)
But in this case, I lost html tags in doc.text, so I no longer have "<b>" which is what I was going to use to indicate section to extract. Is there a way of doing this?
I managed this by following:
singleString <- paste(readLines(myHTMLfile), collapse=" ")
data11 = strsplit(singleString,"<p><b>", fixed = TRUE)
test2<- unlist(data11)
myindex<-regexpr("Myphrase </b>", test2)
I have a scenario where-in I fetch some text from the database which is formatted using HTML as below:
public static void main(String args[ ]) { <br> int x =10;}
I'm using syntax highlighter to do some highlighting. The String above will be fetched from the database, and rendered in the html page using the pre tag as shown below:
<p><pre class="brush: java;">#exam.description</pre></p>
Where exam.description will contain the HTML formatted source code that is shown above. The resultant HTML rendered is as shown below in the screenshot!
How to ensue that the HTML tags inside the source code are respected as HTML tags? I checked the configuration options for the Syntax Highlighter and there seems to be none that I could use to escape the HTML! Any suggestions?
Your question doesn't make much sense, maybe you should rephrase it, in any case:
<p><pre class="brush: java;">Line 1\nLine 2\nLine 3\n</pre></p>
Will return the data in multiple lines, and
<p><pre class="brush: java;">Line 1<br>\nLine 2\nLine 3\n</pre></p>
Will also return multiple lines and add an extra line between Line 1 and Line 2.
So in any case, your code should work UNLESS you are escaping the data returned from the function (java function), and the < and > (or just one of them) are escaped
HTML myHtml=new HTML(SafeHtmlUtils.fromString("<i>Test</i>"));
HTML myHtml2=new HTML("<i>Test2</i>");
testHTMLPanel.add(myHtml);
testHTMLPanel.add(myHtml2);
OUTPUT:
<i>Test</i>
Test2
The right output should be the formmatted text like the second one. Other Gwt html widget also have the similar problem.
I am using Eclipse Juno.
SafeHtmlUtils.fromString(String s)
HTML-escapes its argument and returns the result wrapped as a SafeHtml.
That means that you get somthing like .0;i&#.62;Test&#.60;&#.47;i&.#62;
Check
https://developers.google.com/web-toolkit/doc/latest/DevGuideSecuritySafeHtml
It's a security thing:
The reason why you have SafeHtmlUtils.fromString(userString) is that you can take a dynamic string, for example from a user input, and create a html text from it. It's more safe than just use Html.setText(userString) because with setText(userString) it would be feasible to inject vulnerable code.
more about input validation: http://www.testingsecurity.com/input-validation
I am trying to put a html table into the body of an email. To do this I am trying to build a string that contains the html. I am getting an error though when I try to add a line that includes quotes within the html. How can I ignore these quotes, and just capture the entire line?
BodyRiskMatrix = [BodyRiskMatrix stringByAppendingFormat:#"font-family:"Calibri","sans-serif";}"];
Xcode views the Calibri and sans-serif as variables. Do I need to just delete all of the quotes within the html?
Use a \ before any of your quotes
[BodyRiskMatrix stringByAppendingFormat:#"font-family:\"Calibri\",\"sans-serif\";}"];
this is how you use an escape in C-type languages.
If you want to add HTML to an email you can add an HTML file to your project and then do
[mailController setMessageBody:htmlFile isHTML:YES];