Objective C Building html string - html

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];

Related

Creating new line within a String in HTML

I have string like as follow, which is generated in mvc controller and display in a view within a table cell. S020050A,S020050B,S020050C,S020050D,S020050E,S020050F
,S020050G,S020050H,S020050I,S020050J,S020050K,S020050L
As I want to wrap the text on every 5 words, I have pushed
tag on every 5 words, so that string look like as follow
S020050A,S020050B,S020050C,S020050D,S020050E,S020050F
,S020050G,S020050H,S020050I,S020050J,S020050K,S020050L
I am intended to break the line from there, but in a view it just shows as it is, tag not interpreted as new line but simply as a part of string
I tried putting Environment.Newline and /n as well, when I did this in simple html page, it worked, so I believe it asp.net own mechanism which suppress tag, how I can make tag interpreted as new line?
I could solve it, from controller code (back end) add -> \n instead where you want line break and then in view use this style ->
style="white-space: pre-line"

Freemarker Template return String instead of html element

I am working on Freemarker Template to create one form.
I declared two variables using <#local> which will hold anchor tag and button
<#local rightElement = "<a class='set-right' href='${data.url}'>Forgot your password?</a>">
<#local rightButton = "<input type='button' class='js-show-pass btn-toggle-password btn-link' value='Show'>">
I have used this variable to pass to macro which create my form structure. But when I load my page the variable which I pass prints as String on my Form page. I am accessing them as ${rightElement} and ${rightButton} in my macro. But it is printing my anchor tag with double quotes ,making it as string.
I tried multiple ways to eliminate that double quote with no success. Could you please suggest ways to declare anchor tag in variable and use it as html element and not String.
I'm not sure what you mean by "printing my anchor tag with double quotes, making it as string", but my guess is that the HTML that you print gets auto-escaped, and so you literally see the HTML source (with the <-s and all) in the browser, instead of a link or button.
So, first, assign the values with <#local someName>content</#local> syntax, instead of <#local someName="content">:
<#local rightElement><a class='set-right' href='${data.url}'>Forgot your password?</a></#local>
<#local rightButton><input type='button' class='js-show-pass btn-toggle-password btn-link' value='Show'></#local>
This ensures that ${data.url} and such are properly escaped (assuming you do use auto-escaping, and you should), also then you won't have to avoid/escape " or ' inside the string literal, you can use #if and such in constructing the value, etc.
Then, where you print the HTML value, if you are using the modern version of auto-escaping (try ${.output_format} to see - it should print HTML then, not undefined), you can now just write ${rightElement}, because FreeMarker knows that it's captured HTML, and so needs no more escaping. If you are using the legacy version of auto-escaping (which utilized #escape directive), then you have to write <#noescape>${rightElement}</#noescape>.

Syntaxhighlighter shows up in single line

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

Avoid interpreting HTML code in a QTextBrowser

I have a QTextBrowser in my Qt application. I would like to append some text but, I need part of this text not to be interpreted in HTML. How can I achieve this? May I encode the QString?
If you want your browser not to interpret only parts of your text as HTML you will need to quote the part you want to omit (replace "<" with "&l t;" etc.). You can use convenient escape method:
textBrowser->insertHtml(
QString("<b>this will be bold</b>") +
Qt::escape(QString("<b>this will not</b>"))
);
If you would like not to interpret the whole thing you can insert it as plain text:
textBrowser->insertPlainText ( "<b>foobar</b>" );
Finally I solved my own question using:
QString codedHtml = Qt::escape(html);

Stop HTML Entites

Is there a way to stop a HTML entity from being rendered?
By that I mean that I'd like to have 2 lines. First is where the entity is rendered (e.g. &), and on the second line, I'd like to have the entity itself but not rendered (e.g. & - amp;).
I don't know if it helps, but I'm using WordPress to add both these lines.
Escape the ampersand. For instance, instead of render the ampersand as an entity: &nbsp;.
As per your example, use &amp;.
Simply use htmlentities() in php or htmlspecialchars()
wordpress is in php.so you can use those functions like this :
htmlspecialchars('your tags');