For example:
When typing παιχνιδια.com into Firefox, it is automatically converted to xn--kxadblxczv9d.com
Please suggest a tool for making such a conversion.
One of the easiest is this. Converts and checks for availability at the same time.
If you want to do it inside your browser, save the code in this answer as puny.js and the code below to puny.html, then load the file in your browser.
<html>
<title>Punyconverter</title>
<script type="text/javascript" src="puny.js"></script>
<style type="text/css">
input {width:300px;}
label {width:100px; display:inline-block;}
</style>
<script type="text/javascript">
onload = function( ) {
var ASCII = document.getElementById("ASCII");
var Unicode = document.getElementById("Unicode");
var Input = document.getElementById("Input");
Input.onkeyup=function(){
ASCII.value = punycode.ToASCII( this.value);
Unicode.value = punycode.ToUnicode( this.value);
}
};
</script>
</html>
<body>
<h1>Convert puny coded IDN</h1>
<div><label for="Input">Input</label><input id="Input" type="text"></div>
<div><label for="ASCII">ASCII</label><input id="ASCII" type="text" readonly="readonly"></div>
<div><label for="Unicode">Unicode</label><input id="Unicode" type="text" readonly="readonly"></div>
</body>
You can use any tool that supports "Libidn". A quick search showed SimpleDNS might be of help to you.
There are heaps of converters for IDN online, if that's enough for you, you can use one of them.
Internationalized domain name (i.e. domain names with non-ASCII characters) are encoded using the Punycode system.
You encode and decode IDNA with Python:
>>> print u'παιχνιδια'.encode('idna')
xn--mxaaitabzv9d
>>> print 'xn--mxaaitabzv9d'.decode('idna')
παιχνιδια
The standard modules in Perl also in Apache can do it with the URI module.
use URI;
#insert sitename in next:
$sitename = "..";
my $uri = URI->new( $sitename,'http');
if ($uri->scheme) { print $uri; }
Related
Server: Unix, Client: IE Edge
Part of my code:
%let P_debug_log = %str(<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>);
proc stream outfile=_webout quoting=both resetdelim='_do' ASIS;
BEGIN
%if "&_whattodo" ne "print" %then %do;
<script language='JavaScript' type='text/javascript'>
function subForm(f,v) {
if (v !== '') {
$('#'+ f).append('<INPUT TYPE="hidden" NAME="'+ v +'" VALUE="1">');
}
$('#'+f).submit();
}
$(document).ready(function() {
$('#footButtons').append($('.footButton')); /* move all elements with class=footButton to pageFooter */
$('#footMessage').append($('.footMsg'));
$('form.log').append("&P_debug_log.");
});
</script>
%end;
;;;;
Output:
The Problem is, that generated stream Output has linebreaks "somewhere" but not where expected (with Option ASIS it should be formatted like in my code).
This leads to unpredictable JavaScript Errors, e.g. when a linebreak is within a JavaScript string.
It seems as if there is an implicit LRECL 1024. This would be OK if linebreaks would be set as expected.
Any hints?
This is the originally formatted Output (Page Source):
<script language='JavaScript' type='text/javascript'> function subForm(f,v) { if (v !== '') { $('#'+ f).append('<INPUT TYPE="hidden" NAME="'+ v +'" VALUE="1">'); } $('#'+f).submit(); }
$(document).ready(function() { $('#footButtons').append($('.footButton')); $('#footMessage').append($('.footMsg')); $('form.log').append("
<INPUT TYPE=
'hidden
' NAME=
'_DEBUG
' VALUE=
'LOG
'
>"); }); </script>
Not sure if I have an answer, but it looks like the macro quoting is what is causing PROC STREAM to separate out the macro variable into multiple lines.
So if I run this simplified example:
%let P_debug_log = %str(<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>);
filename tst temp;
proc stream outfile=tst quoting=both resetdelim='_do' ASIS;
BEGIN
$('form.log').append("&P_debug_log.");
;;;;
Then it generates this file:
$('form.log').append("
<INPUT TYPE='hidden
' NAME='_DEBUG
' VALUE='LOG
'>");
If you remove the %STR() from around the value of the macro variable then it only inserts line breaks before and after the full macro variable reference and not also around the quotes in the macro variable.
$('form.log').append("
<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>
");
If you remove the quoting=both option then the line breaks will be outside the quotes, whether or not you use macro quoting.
$('form.log').append(
"<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>"
);
First of all, thank you all for your answers.
Robert Penridge was right.
Solution:
If you use PROC STREAM and want to include static code (as in my case: Javascript), then use &STREAMDELIM READFILE instead of %include.
Reason: if there are (valid!) inline comments "//" (comment until next linebreak,) in the included code, it will lead to unpredictable results....
thanks a lot,
dbdb
Simply remove the ASIS option you have added to proc stream.
I'm not sure if this is an undocumented feature but it doesn't appear in the documentation so I'm assuming so.
http://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n12zrkr08eiacmn17lcv4fmt79tb.htm&locale=en
Once you remove that the weird line breaks disappear.
Searching around, it appears the ASIS option is something to do with attempting to preserve column alignment.
I have the following Sightly template:
<body>
<script type="application/json" id="test">
[
{
"url": "${test}"
}
]
</script>
</body>
I want to escape the value of 'test' using JSON style escaping. Unfortunately, using context='scriptString' escapes a dash as '\-', which is invalid JSON.
How can I use JSON style escaping on this value?
You need to use context='unsafe' to write JSON like this:
${test # context='unsafe'}
Sightly uses OWASP Encode#forJavascript() for the scriptString context. It seems to be a bug or a missing documentation about escaping dashes.
For URLs you can use context='uri'. For plain text you can use context='text'.
line breaks or pharagraph not working in textarea output? for example i am using enter for pharagraph in textarea but not working in output? How can i do that?
$("#submit-code").click(function() {
$("div.output").html($(".support-answer-textarea").val());
}).next().click(function () {
$(".support-answer-textarea").val($("div.output").html());
});
.support-answer-textarea{width:100%;min-height:300px;margin:0 0 50px 0;padding:20px 50px;border-top:1px solid #deddd9;border-bottom:1px solid #deddd9;border-left:none;border-right:none;box-sizing:border-box;letter-spacing:-1px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<textarea id="support-answer-textarea" class="support-answer-textarea" placeholder="Destek Konusunu Cevapla!"></textarea>
<button type="submit" id="submit-code" class="btn btn-success">Submit Your Code</button>
<div class="output"></div>
The best and easy way to fix line breaks on the output use these simple css:
.support-answer-textarea {
white-space: pre-wrap;
}
When you hit enter in a <textarea>, you're adding a new line character \n to the text which is considered a white space character in HTML. HTML generally converts the sequence of all white spaces to a single space. This means that if you enter a single or a dozen of whitespace characters (space, new line character or tab) in a row, the only effect in resulting HTML is just a single space.
Now the solution. You can substitute the new line character (\n) to <br> or <p> tag using replace() method.
$("#submit-code").click(function() {
$("div.output").html($(".support-answer-textarea").val().replace(/\n/g, "<br>"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<textarea id="support-answer-textarea" class="support-answer-textarea"></textarea>
<button type="submit" id="submit-code">Submit Your Code</button>
<div class="output"></div>
for me, I had a e.preventDefault() for only Enter keypress on a parent element, this prevents a new line from adding.
If you are capturing an input from a textarea, sending it via ajax (saving to database, e.g. mysql) and then want to display the result in a textarea (e.g. by echoing via php), use the following three steps in your JS:
#get value of textarea
var textarea_value = $('#id_of_your_textarea').val();
#replace line break with line break input
var textarea_with_break = textarea_value.replace(/(\r\n|\n|\r)/gm, '
');
#url encode the value so that you can send it via ajax
var textarea_encoded = encodeURIComponent(textarea_with_break);
#now send via ajax
You can also perform all of the above in one line. I did it in three with separate variables for easier readability.
Hope it helps.
Posting this here as it took me about an hour to figure this out, fumbling together the solutions from the answers below (see for more details):
The .val() of a textarea doesn't take new lines into account
New line in text area
URL Encode a string in jQuery for an AJAX request
I want to put a packman game on my *.xhtml page.(I am using jsf 2 and primefaces 3.5)
However,
when I "translated" the html page in xhtml I get an error at this script:
<script>
var el = document.getElementById("pacman");
if (Modernizr.canvas && Modernizr.localstorage &&
Modernizr.audio && (Modernizr.audio.ogg || Modernizr.audio.mp3)) {
window.setTimeout(function () { PACMAN.init(el, "./"); }, 0);
} else {
el.innerHTML = "Sorry, needs a decent browser<br /><small>" +
"(firefox 3.6+, Chrome 4+, Opera 10+ and Safari 4+)</small>";
}
</script>
At line:
if (Modernizr.canvas && Modernizr.localstorage &&
i get:
The entity name must immediately follow the '&' in the entity
reference.
Any idea how to fix that?
All answers posted so far are giving the right solutions, however no one answer was able to properly explain the underlying cause of the concrete problem.
Facelets is a XML based view technology which uses XHTML+XML to generate HTML output. XML has five special characters which has special treatment by the XML parser:
< the start of a tag.
> the end of a tag.
" the start and end of an attribute value.
' the alternative start and end of an attribute value.
& the start of an entity (which ends with ;).
In case of & which is not followed by # (e.g. , , etc), the XML parser is implicitly looking for one of the five predefined entity names lt, gt, amp, quot and apos, or any manually defined entity name. However, in your particular case, you was using & as a JavaScript operator, not as an XML entity. This totally explains the XML parsing error you got:
The entity name must immediately follow the '&' in the entity reference
In essence, you're writing JavaScript code in the wrong place, a XML document instead of a JS file, so you should be escaping all XML special characters accordingly. The & must be escaped as &.
So, in your particular case, the
if (Modernizr.canvas && Modernizr.localstorage &&
must become
if (Modernizr.canvas && Modernizr.localstorage &&
to make it XML-valid.
However, this makes the JavaScript code harder to read and maintain. In case when you want to continue using & instead of & in JavaScript code in a XML document, then you should be placing the JavaScript code in a character data (CDATA) block. Thus, in JSF terms, that would be:
<h:outputScript>
<![CDATA[
// ...
]]>
</h:outputScript>
The XML parser will interpret the block's contents as "plain vanilla" character data and not as XML and hence interpret the XML special characters "as-is".
But, much better is to just put the JS code in its own JS file which you include by <script src>, or in JSF terms, the <h:outputScript>.
<h:outputScript name="onload.js" target="body" />
(note the target="body"; this way JSF will automatically render the <script> at the very end of <body>, regardless of where <h:outputScript> itself is located, hereby achieving the same effect as with window.onload and $(document).ready(); so you don't need to use those anymore in that script)
This way you don't need to worry about XML-special characters in your JS code. As an additional bonus, this gives you the opportunity to let the browser cache the JS file so that total response size is smaller.
See also:
Error Parsing /page.xhtml: Error Traced[line: 42] The entity "nbsp" was referenced, but not declared
Is it possible to use JSF+Facelets with HTML 4/5?
How to reference CSS / JS / image resource in Facelets template?
You need to add a CDATA tag inside of the script tag, unless you want to manually go through and escape all XHTML characters (e.g. & would need to become &). For example:
<script>
//<![CDATA[
var el = document.getElementById("pacman");
if (Modernizr.canvas && Modernizr.localstorage &&
Modernizr.audio && (Modernizr.audio.ogg || Modernizr.audio.mp3)) {
window.setTimeout(function () { PACMAN.init(el, "./"); }, 0);
} else {
el.innerHTML = "Sorry, needs a decent browser<br /><small>" +
"(firefox 3.6+, Chrome 4+, Opera 10+ and Safari 4+)</small>";
}
//]]>
</script>
The parser is expecting some HTML content, so it sees & as the beginning of an entity, like è.
Use this workaround:
<script type="text/javascript">
// <![CDATA[
Javascript code here
// ]]>
</script>
so you specify that the code is not HTML text but just data to be used as is.
Do
<script>//<![CDATA[
/* script */
//]]></script>
If you use XHTML, for some reason, note that XHTML 1.0 C 4 says: “Use external scripts if your script uses < or & or ]]> or --.” That is, don’t embed script code inside a script element but put it into a separate JavaScript file and refer to it with <script src="foo.js"></script>.
Just in case someone from Blogger arrives, I had this problem when using Beautify extension in VSCode. Don´t use it, don´t beautify it.
Given that I have a string being displayed on the page in AngularDart.
... <strong>Notes: </strong> {{cmp.selectedStudent.notes}} ...
How can I make it display multi-line? In the string I have newline characters, I want them to be encoded as <br /> characters in the html output.
You can replace the '\n' in your string with <br/> and use something like the proposed my-bind-html directive shown in my answer here How to add a component programatically in Angular.Dart? (the code might be a bit outdated due to a lot of recent changes in Angular)
You could use ng-repeat and repeat over your notes lines but first you need to split them by '\n' so you get an array of lines.
List<String> _notesList = null;
List<String> get notesList {
if (_notesList==null) _notesList = notes.split("\n").toList(); return _notesList;
}
.
<span ng-repeat="note in cmp.selectedStudent.notesList">{{note}}<br /></span>
By default, angular doesn't interpret HTML balise to avoid some unpredictible behavior or others bad thing, but you can disable this verification with
ng-bind-html
link to the official doc : NgHtmlBind
So you can replace directly the '\n' character by the 'br' html node.
So you can do :
// ...
String getHtmlBrNote() {
return this.notes.replaceAll("\n", "<br />");
}
// ...
and after in angular
... <strong>Notes: </strong> <span ng-bind-html="cmp.selectedStudent.getHtmlBrNote()"></span> ...
And it will be ok