Single quotes (') is replaced by ' - html

I am using a third party jar file to generate svg file. I am expecting something like myfunction('divId'); But output is coming as myfunction('divId'); Is there any way to avoid '.

Assuming you're using Java (jar file), you could call String#replace() like so -
String str = "myfunction('divId');";
str = str.replace("'", "'");
System.out.println(str);
Outputs
myfunction('divId');

Perhaps you can try defining a character set (i.e., <meta charset="UTF-8">) in your document header.

&apos and &amp are not in the list of HTML4 entities, use &#39 instead.
myfunction(&#39divid&#39)
should work.

Related

HTML: show > in plain text

In HTML files, if I want the browser to show a special symbol, such as >, I can use the special escape character sequence > and the browser will automatically transform it to >.
But what if I don't want it to be transferred into >? What if I happen to want the character sequence to be shown in plain text?
In order to have a character sequence not automatically rendered as a symbol, you can escape out the ampersand. This method is commonly used by instructional pages with lists of HTML symbols.
Source: >
Result: >
Source: &gt;
Result: >
Thanks to Ry-♦ for stating the obvious. I was so concerned about using raw string, I didn't realize what I was using is adequate already. Use .textContent property to render text as is. If you use something like .innerHTML, it will parse your text as HTML and apply escape sequences.
Demo
var str = ">"
document.querySelector('body').textContent = str;

Escape HTML text

I am writing html files from a stack. This is a bit of a pain because for every line I have to write something like the following if the file contains quotes.
write "<div id=hidden-" & quote & myKanton & quote && "style=" & quote & "display:block;" &quote&&"class=" &quote & "popuptable" &quote& ">" & LF to file tOutputFileCH
Now I have to add a lot of html code again and I'm wondering if there is an easier way to be able to do something like:
write escaped("my html numbers and "txt" with quotes") to file
I do not need variables within the html text.
Often, people use functions like
function q theText
replace "'" with quote in theText
return theText
end q
which can be used as
write q("<div id=hidden-'" & myKanton & "' style='display:block;'" & "class='popuptable'>" & LF) to file tOutputFileCH
You can use a string like in above example but you can also use any container:
get q(myVariable)
put q(it) into field 1
put q(field 1) into field 2
put q(url myUrl) into url myOtherUrl
put q(the cProperty of me) into myVar
-- etc etc etc
You can also use ´ or ` instead of ' if you change the q function.
By the way, I noticed that you don't include hidden- in the quotes. Are you sure that's correct?
HTML allows use of quotes and single quotes, so you can...
put "<div style='border:1px'>" into tHTML
LiveCode's format command allows you to escape double quotes...
put format("my html numbers and \"txt\" with quotes") into tData
It is working now. I put the html lines in a custom stack property and use that as input when writing the file. Works perfectly. It even seems to work without the q function.
write ( the cMapOverlay of stack "AfaConverter" ) & LF to file tOutputFileCH
I also tried that because
onmouseover="nhpup.popup($('#hidden-VS').html(), {'width': 400});" href="./kantone/index_kanton_VS.html"
this is trouble with q without adaptions because ' is replaced with " which is a problem.
There are some good answers here. Let me suggest another approach. You could use a quoting function, but in a slightly different way:
function q pString
return quote & pString & quote
end q
Then use the LiveCode merge() function. Merge evaluates any LiveCode expression or variable enclosed in [[ ]] and incorporates it into the enclosing quoted text:
write merge("my html numbers and [[q("txt")]]") to file

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

Encode HTML before POST

I have the following script, which encodes some of the value it receives propertly, but it does not seem to encode double quotes.
How do I encode the full value properly before posting?
function htmlEncode(value){
return $('<div/>').text(value).html();
}
The above script give me this:
<p>Test&nbsp; <span style="color: #ffffff"><strong><span style="background-color: #ff0000">1+1+1=3</span></strong></span></p>
I need it to give me this:
<p>Test&nbsp; <span style="color: #ffffff"><strong><span style="background-color: #ff0000">1+1+1=3</span></strong></span></p>
EDIT: Followup question:
Encoded HTML in database back to page
You shouldn't try to encode things with JavaScript.
You should encode it serverside.
Anything that can be done with JavaScript can be undone.
It is valid to encode it in JavaScript if you also check that it was encoded on the server, but keep in mind: JavaScript can be disabled.
What George says is true.
But, if you have to encode strings client-side, I'd suggest you use JavaScript's encodeURIComponent().
I had a similar problem. I simply used the replace method in javascript. Here's a nice article to read: http://www.w3schools.com/jsref/jsref_replace.asp
Basically what the replace method does is it swaps or replaces the character it founds with what you indicate as replacement character(s).
So this:
var str=' " That " ';
str = str.replace(/"/g,'"');
Once you log this into the console of your browser, you will get something like
" That "
And this:
var str=' " That " ';
str = str.replace(/"/g,'blahblahblah');
Once you log this into the console of your browser, you will get something like
blahblahblah That blahblahblah
You can use this module in js, without requiring jQuery:
htmlencode
You can re-use functions from php.js project - htmlentities and get_html_translation_table
Use escape(str) at client side
and
HttpUtility.UrlDecode(str, System.Text.Encoding.Default); at server side
it worked for me.

How to add non-escaped ampersands to HTML with Nokogiri::XML::Builder

I would like to add things like bullet points "•" to HTML using the XML Builder in Nokogiri, but everything is being escaped. How do I prevent it from being escaped?
I would like the result to be:
<span>•</span>
rather than:
<span>&#8226;</span>
I'm just doing this:
xml.span {
xml.text "•\ "
}
What am I missing?
If you define
class Nokogiri::XML::Builder
def entity(code)
doc = Nokogiri::XML("<?xml version='1.0'?><root>&##{code};</root>")
insert(doc.root.children.first)
end
end
then this
builder = Nokogiri::XML::Builder.new do |xml|
xml.span {
xml.text "I can has "
xml.entity 8665
xml.text " entity?"
}
end
puts builder.to_xml
yields
<?xml version="1.0"?>
<span>I can has • entity?</span>
PS this a workaround only, for a clean solution please refer to the libxml2 documentation (Nokogiri is built on libxml2) for more help. However, even these folks admit that handling entities can be quite ..err, cumbersome sometimes.
When you're setting the text of an element, you really are setting text, not HTML source. < and & don't have any special meaning in plain text.
So just type a bullet: '•'. Of course your source code and your XML file will have to be using the same encoding for that to come out right. If your XML file is UTF-8 but your source code isn't, you'd probably have to say '\xe2\x80\xa2' which is the UTF-8 byte sequence for the bullet character as a string literal.
(In general non-ASCII characters in Ruby 1.8 are tricky. The byte-based interfaces don't mesh too well with XML's world of all-text-is-Unicode.)