I'm trying to use em dash (—) and multiplication symbol (×) in my Velocity template. But the output gives the following.
— for em dash
× for multiplication symbol
I have added <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> in the <head/> as well.
I tried using the following as well.
#set( $multiplySymbol = '×' )
But it gives the same output.
How to use these kind of special characters on Velocity?
Used the following when getting the template vm file.
Template template = Velocity.getTemplate("template.vm", "UTF-8");
Thanks #user7294900
Related
i'm trying to list all product from my databse. All my page is display well but for my list the UTF-8 encoding doesn't seems to work. I'm french so i use some "é è ê"..
So when i'm doing something like
<div class ="notrelevent"> Général </div>
it works great but when i do something like
`<tr v-for="product in products | paginate" :product="product"></tr> `
I have bad result like : this is a test � again cr�me
Or i should get :
this is a test à again crème
Thanks for the help
1) In your HTML section, you should put this:
<meta charset="utf-8">
2) Any database call should be done with a client using utf8.
Open the file in Notepad++, go to "Encoding" -> "Convert to UTF-8" and then save the file, and problem solved
I'm having a weird problem that is getting me really really confused here.
I'm working on internationalization of a web app, and implementing UTF-8 all over.
The app has a lot of legacy code in Classic ASP, which is working fine so far.
What is getting me confused here is the following.
From the admin side of the APP I'm saving this string to test special characters:
Á, É, Í, Ó, Ú, Ü, Ñ ± ' Z Ž
If I run the SQL Server Profiler, I do not see the Ž character being inserted
If I do a Response.Write of the query that is running the UPDATE, the character is there
If I try to edit what was saved from the web front end, the character is there.
If I check the HTML Source code of the page I'm editing the character is correctly encoded as HTML using Server.HTMLEncode
If I run a select query from SQL Server Management Studio I do not see the character
I have the html meta tag to set UTF-8
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
The files are saved with UTF-8 Encoding
How can it be that the character is not visible in SQL Server Profiler or queries but if I do it from the front end the character is there?
I'm using the N prefix to save unicode in SQL Server and the column is of type nvarchar(128)
Then from another part of the system with the same setup if I try to do the same thing, the character is visible when doing the insert.
Any ideas?
I'm outputting a Word (docx) file using docx4j, and the page breaks aren't appearing in the document.
I'm using:
hr {page-break-after: always}
for the css, but it isn't rendering as a page break in the Word document.
What html or css should I be using to get an html page break to transfer over to the docx file?
Worked for me, try to use this tag:
<br style=\"page-break-after: always; clear:both;\"></br>
All other tag not worked with style css.
Works with heading tags or paragraph tags (h1, h2, p):
I used this css style with h1 tags in my html content and successfully got the page-breaks applying after the heading in my exported word document:
String pageBreakMarker = "<h1 style=\"page-break-after: always;\"></h1>";
I think this is not working with html break tags has to do with how docx4j treats html break tags.
Even looking at the getting started sample on github, I only see the 'page-break-after' or 'page-break-before' being used with only html paragraph tags (p)
See link to Docx4j getting started guide on github below:
Docx4j Getting Started
Does not work with html break tags:
Using docx4, I can confirm I the "page-break-after" or "page-break-before" does not work when trying to create page breaks in word docs from html content with break tags (hr):
<br style=\"page-break-after: always; clear:both;\"></br>
Simply add this line before heading tags or paragraph tags (h1, h2, p) :
<p style="line-height: 100%; margin-bottom: 0mm; page-break-before: always">
When i open it in OpenOffice writer, it breaks the page.
I have an ASP Classic app that allows people to copy and paste Word documents into a regular form field. I then post that document via jQuery Ajax to SQL Server, where the information is saved.
My problem is that the curly quotes and other word characters turn into strange characters when they come back out.
I'm trying to filter them on my save routines (classic asp stored procedure), but I still can't quite eliminate the problems.
The ASP pages have this header with the ISO-8859-1 charset. Characters look fine when pasted into the text input fields.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
My jQuery code builds the following JSON in the ASP Page:
var jsonToSend = { serial: serial, critiqueText: escape(critiqueText) };
The database collation is set to SQL_Latin1_General_CP1_CI_AS
I use TEXT and VARCHAR fields to hold the text (yes, I know the Text field type is not preferred, but it's what I have right now).
What must I do at each point to ensure that (1) the Word characters are stripped out, and (2) the encoding is consistent from front to back so I don't get any odd characters displaying?
Oh- ASP Classic 3 running in 32-bit mode on Windows Server 2003 against SQL Server 2005.
Quick and dirty solution would be using nvarchar and ntext in your backend database. Strange chars you mention is problem of encoding. For example see below example.
İiıIÜĞ in turkish language win-1254
Ä°iıIÃœÄ in normal ANSI
C4B069C4B149C39CC49E both of them have same hex value.
You use ISO-8859-1 encoding in web page. This means that you are only able to save only ASCII characters that is only first 256 bit of full unicode. See this answer.
You use Latin1 in database. Approximately this three characters sets are equal. Latin1-General = Win 1252 = IEC_8859-1.
ISO/IEC_8859-1 is the basis for most popular 8-bit character sets, including Windows-1252 and the first block of characters in Unicode.
SQL_Latin1_General_CP1_CI_AS:- Latin1-General, case-insensitive, accent-sensitive, kanatype-insensitive,
width-insensitive for Unicode Data, SQL Server Sort Order 52 on Code Page 1252 for non-Unicode Data
This means that whatever character you entered to database first 256 bits values are safe. If you know your client's default encodings.
I suggest to try this default encoding to see if you can recover some information.
I gave example in Turkey, I know that most client's use Win1254 therefore I will try to change values to that encoding and see I can recover anything.
Second part of your answer is that you can safely change from varchar to nvarchar without loss of information.
Here this without loss of information would be first part hex value (first 256 value).
Your strange chars would remain but other characters stays.
This answer and linked article gives more information.
You should not use the javascript function escape, it uses non-standard encoding that is a mix of standard URL encoding using ISO-8859-1 and a weird %uxxxx scheme for anything not in ISO-8859-1.
Additionally, you should not manually escape anything at all, since jQuery will use proper escaping on your jsonToSend-object anyway.
So when you do this:
var jsonToSend= { serial: serial, critiqueText: escape(critiqueText) } ;
$.post( "example.asp", jsonToSend );
And critiqueText is, say, “hello world”. First the escape will turn it into:
%u201Chello%20world%u201D
Then jQuery will apply standard URL encoding on that before sending and it will become:
%25u201Chello%2520world%25u201D
So simply change your jsonToSend to:
var jsonToSend= { serial: serial, critiqueText: critiqueText) } ;
Which results in
%E2%80%9Chello%20world%E2%80%9D
I.E. standard URL encoding, you can even point your browser to http://en.wikipedia.org/wiki/%E2%80%9Chello%20world%E2%80%9D
Note, it's likely that Classic ASP won't recognize standard URL encoding, so here's a function to apply Win1252 URL encoding:
var map = {
0x20AC: 128,
0x201A: 130,
0x0192: 131,
0x201E: 132,
0x2026: 133,
0x2020: 134,
0x2021: 135,
0x02C6: 136,
0x2030: 137,
0x0160: 138,
0x2039: 139,
0x0152: 140,
0x017D: 142,
0x2018: 145,
0x2019: 146,
0x201C: 147,
0x201D: 148,
0x2022: 149,
0x2013: 150,
0x2014: 151,
0x02DC: 152,
0x2122: 153,
0x0161: 154,
0x203A: 155,
0x0153: 156,
0x017E: 158,
0x0178: 159
};
function urlEncodeWin1252( str ) {
return escape( str.replace( /[\d\D]/g, function(m){
var cc = m.charCodeAt(0);
if( cc in map ) {
return String.fromCharCode(map[cc]);
}
return m;
}));
}
You still can't have jQuery double encoding the result from this, so pass it a plain string:
var jsonToSend= "serial=" + serial + "&critiqueText=" urlEncodeWin1252(critiqueText);
Which will result in:
serial=123&critiqueText=%93hello%20world%94
You might want to rename that variable, there is no JSON anywhere.
I deal with importing of crazy characters into SQL all day long and nvarchar is the way to go. Unless they're numbers or something of that sort I set the columns to nvarchar(max) so I won't have to deal with it. The only exception you have to keep in mind is if you're going to use Foreign Keys then you'll have to set it to nvarchar(450). This handles all kinds of crazy characters, spacing, and gaps in text as the result of tabs.
I am using HandleBar.js in my rails jquery mobile application.
I have a json returned value data= "hi\n\n\n\n\nb\n\n\n\nhow r u"
which when used in .hbs file as {{data}} showing me as hi how r u and not as with the actual new line inserted
Please suggest me.
Pre tag helps me
Handlebars doesn't mess with newlines in your data unless you have registered a helper which is doing something with them. A good way of dealing with newlines in HTML without converting them to br tags would be to use the CSS property white-space while rendering the handlebars template in HTML. You can set its value to pre-line.
Read the related documentation on MDN
Look at the source of the generated file - your newline characters are probably there, HTML simply does not render newline characters as new lines.
You can insert a linebreak with <br />
However, it looks like you're trying to format the position of your lines using newline characters, which technically should be done by wrapping your lines in <p> or <div> tags and styling with CSS.
Simply use the CSS property white-space and set the value as pre-line
For a example:
<p style="white-space: pre-line">
{{text}}
</p>