jQuery FullCalendar accents in dayView - fullcalendar

I think this is a bug.
I setup the names (in italian) of days:
dayNames:['Domenica','Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato']
The name is shown correctly in the header of dayView but not in the subheader.
Does anybody know why?

Same problem. I solved by changing the function "htmlEscape" in file fullcalendar.js
I add:
.replace(/ì/g, 'ì')
the function now work correctly for me (i need the italian language in my application), but you must add the character to correctly encod in the day names
function htmlEscape(s) {
return (s + '').replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/'/g, ''')
.replace(/"/g, '"')
.replace(/ì/g, 'ì')
.replace(/\n/g, '<br />');
}

Way simpler:
Add <meta charset="utf-8"> to the <head> of your html file

I tried the htmlEscape function modified by user3514257 but I found an error.
This is my function:
function htmlEscape(s) {
return (s + '').replace(/ì/g, 'ì')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/'/g, ''')
.replace(/"/g, '"')
.replace(/&/g, '&')
.replace(/\n/g, '<br />');
}
I change the first line with the ì line because the & character did not allow recognizing of ì

Related

if else statement gives array

I made this code to below. But it isn't working. Its giving an array.
Can somebody help me with this?
<?php
/**
*$fields['listcheckbox_1574292451270']
*/
$Extra_1 = $fields['listcheckbox_1574292451270'];
if ($Extra_1 == "1_1") {
echo ("Correct");
} elseif ($Extra_1 == "2_2") {
echo ("True");
} else {
echo ("False");
}
?>
I tried to put at the last else echo = "$1_extra"; but that gave an Array.
$fields[listcheckbox_1574292451270] is a checkbox with multiple options "1_1" & "2_2"
If this code isn't any good, can somebody help me with it?
Thanks
shouldn't that first line be:
$1_extra = $fields['listcheckbox_1574292451270'];
I think you missed the ' when accessing that array.
Edit: just noticed a few things:
if echo $1_extra; outputs Array - to see the actual values of it you either need to convert the array to a string or iterate over it. For debugging array values you can use var_dump($1_extra); which provides more information than echo does.
After that you should also see how to access the data inside your array. You can read more about working with arrays in php here: https://www.php.net/manual/en/language.types.array.php

R Paste " " around string

I create a function and need to paste " " around the string, the final desired code is 'table_df' in the following code
if (exists('table_df') && is.data.frame(get('table_df'))&nrow(table_df)>0) {
tracking_sheet$var1[tracking_sheet$var2=="table_name"]<-'Completed'
} else {tracking_sheet$var1[tracking_sheet$var2=="table_name"]<-'Check'}
this is my function, but it doesnt work, mainly because of the quotes around the string part. paste('", table_df, "',sep=""), so my question is how to use paste or other function to achieve the final result 'table_df'
check<-defmacro(tracking_sheet,table_df,table_name,
expr={if (exists(paste('", table_df, "',sep="")) && is.data.frame(get(paste('", table_df, "',sep="")))&nrow(table_df)>0) {
tracking_sheet$var1[tracking_sheet$var2==table_name]<-'Completed'
} else {tracking_sheet$var1[tracking_sheet$var2==table_name]<-'Check'}
})
check(tracking_sheet,app_df_pivot,"T_Applications")
the code above is trying to create a summary sheet to report which dataframe is existed in the environment and if the df contains data. I am welcome to all advice and thank you!
I think you mean to use
paste('"', table_df, '"',sep="")
Without the closing single-quotes,
paste('", table_df, "',sep="")
evaluates to ", table_df, "
If you want to paste a quote, you have to escape it with "\"
paste0("\'", "example", "\'")

Html Table export to PDF with iTextSharp Library Chinese Character not show [duplicate]

I'm facing a problem when trying to export a Vietnamese document as PDF using iText.
I put Vietnamese words in .xml file like this
<td fontfamily="Helvetica" fontstyle="0" fontsize="9" align="0" colspan="48" lineoccupied="1">T\u1ED5 ch\u1EE9c tham gia</td>
then having java to get the phrases from xml file and convert it into Unicode using this method:
public String convertToUnicode(String s) {
int i = 0, len = s.length();
char c;
StringBuffer sb = new StringBuffer(len);
try {
while (i < len) {
c = s.charAt(i++);
if (c == '\\') {
if (i < len) {
c = s.charAt(i++);
if (c == 'u') {
if (Character.digit(s.charAt(i), 16) != -1
&& Character.digit(s.charAt(i + 1), 16) != -1
&& Character.digit(s.charAt(i + 2), 16) != -1
&& Character.digit(s.charAt(i + 3), 16) != -1) {
if (s.substring(i).length() >= 4) {
c = (char) Integer.parseInt(s.substring(i, i + 4), 16);
i += 4;
} else {
sb.append('\\');
}
} else {
sb.append('\\');
}
} // add other cases here as desired...
}
} // fall through: \ escapes itself, quotes any character but u
sb.append(c);
}
} catch (Exception e) {
System.out.println("Error Generate PDF :: " + e.getStackTrace().toString());
return s;
}
return sb.toString();
}
After that, export String to PDF - encoding UTF-8.
But the program failed to display Vietnamese character '\u1ED5' and '\u1EE9'
The output becomes "T chc tham gia"
Could you please show me how to fix this issue?
Thanks :)
There are 3 XML Worker examples involving Asian languages on the official iText web site. They parse an XHTML file containing Chinese characters, but it should be easy to adapt them to Vietnamese examples.
You can find the HTML files were going to parse here:
hero.html
hero2.html
Both files contain the following text:
長空 (Broken Sword), 秦王殘劍 (Flying Snow), 飛雪 (Moon), 如月 (the King), and 秦王 (Sky).
In the first case, a font is defined using CSS:
<span style="font-size:12.0pt; font-family:MS Mincho">長空</span>
In the second case, no specific font is defined:
<body><p>長空 (Broken Sword), 秦王殘劍 (Flying Snow), 飛雪 (Moon), 如月 (the King), and 秦王 (Sky).</p></body>
These files contain UTF-8 characters, so we're going to parse them like this:
XMLWorkerHelper.getInstance().parseXHtml(writer, document,
new FileInputStream(HTML), Charset.forName("UTF-8"));
The first thing you need, is a font that supports Vietnamese characters. That's something iText can't help you with. In your HTML file, you've defined Helvetica, but that's a standard Type1 font that is never embedded when using iText and that doesn't know how to draw Vietnamese glyphs. That's never going to work.
The first example D07_ParseHtmlAsian will automatically search for a font named MS Mincho. If it finds that font (for instance because you have msmincho.ttc in your Windows fonts directory), the font will show up in your PDF. See hero.pdf. If it doesn't find a font with that name, then the glyphs won't be visible, because you didn't provide any font program for those glyphs.
The second example D07bis_ParseHtmlAsian offers a workaround in case you don't have MS Mincho anywhere. In that case, you have to use an XMLWorkerFontProvider and register a font that can be used instead of MS Mincho. For instance: we use a font stored in the file cfmingeb.ttf and assign the alias MS Mincho:
XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
fontProvider.register("resources/fonts/cfmingeb.ttf", "MS Mincho");
The resulting file asian.pdf is slightly different from what we expect, but now we can at least see the Chinese glyphs.
In the third example, the HTML file doesn't tell us anything about the font that needs to be used. We'll define the font using CSS like this:
CSSResolver cssResolver = new StyleAttrCSSResolver();
CssFile cssFile = XMLWorkerHelper.getCSS(new ByteArrayInputStream("body {font-family:tsc fming s tt}".getBytes()));
cssResolver.addCss(cssFile);
Now, all the text in the body will use the font TSC FMing S TT (stored in the file cfmingeb.ttf). You can see the difference in the resulting PDF asian2.pdf.
I think you need an encoding as UTF-8 for your HTML and use &#xUNUM; for hex or &#NUM; for regular code to embed your special characters. Not sure where but somewhere in your program since it is not display shown, but your final HTML should be:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML LEVEL 1//EN">
<HTML>
<HEAD>
<TITLE>Your Page Title</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
</HEAD>
<BODY>
<!-- YOUR CONTENT HERE -->
<td fontfamily="Helvetica" fontstyle="0" fontsize="9"
align="0" colspan="48"
lineoccupied="1">Tổ chức tham gia</td>
</BODY>
</HTML>
You can cut and paste the above into an HTML file and view the result. More reading pleasure is here Unicode and HTML

Problem with quotes in "onclick" function

I'm trying to concatenate PHP variables into an "onclick" function.
Here is the line I'm having trouble with (look for the "onclick" part):
$imagecontent = '<div class="imagensfw" id="image'.$id.'" style="width:'.round($wd).'px;height:'.round($ht).'px;" onclick="viewimage(image'.$id.','.round($wd).','.$url.');"><p>Image</div>';
I'm particularly having trouble with concatenating the $url variable. I'd want to put it between quotes, but if I do so, the "onclick" function becomes all messed up (when the code is displayed in the browser).
I think that putting the URL address ($url variable as a parameter in the onclick) between quotes will fix the error its shooting:
Error : missing ) after argument list
Here's my short Javascript function if you're interested:
function viewimage(id,width,url){
var image = document.getElementById(id);
image.innerHTML = '<img src="'+url+'" width="'+width+'" alt="Image" />';
}
Here's what I tried but didn't work (i.e. messed up the code):
onclick="viewimage(image'.$id.','.round($wd).', **"** '.$url.' **"** );"
(Noticed the double quotes added between the $url variable).
Thank you for your time.
Have you tried using variable parsing? From the link's example:
$beer = 'Heineken';
echo "He drank some ${beer}s";
This should simplify the construction of your string.
Silly me, I just noticed an error on my part. I thought we could use double quotes in an "onclick" function. Turns out not, we have to use single quotes ( ' ). It fixed my problem. Thanks!

Using Vim, how can I make CSS rules into one liners?

I would like to come up with a Vim substitution command to turn multi-line CSS rules, like this one:
#main {
padding: 0;
margin: 10px auto;
}
into compacted single-line rules, like so:
#main {padding:0;margin:10px auto;}
I have a ton of CSS rules that are taking up too many lines, and I cannot figure out the :%s/ commands to use.
Here's a one-liner:
:%s/{\_.\{-}}/\=substitute(submatch(0), '\n', '', 'g')/
\_. matches any character, including a newline, and \{-} is the non-greedy version of *, so {\_.\{-}} matches everything between a matching pair of curly braces, inclusive.
The \= allows you to substitute the result of a vim expression, which we here use to strip out all the newlines '\n' from the matched text (in submatch(0)) using the substitute() function.
The inverse (converting the one-line version to multi-line) can also be done as a one liner:
:%s/{\_.\{-}}/\=substitute(submatch(0), '[{;]', '\0\r', 'g')/
If you are at the beginning or end of the rule, V%J will join it into a single line:
Go to the opening (or closing) brace
Hit V to enter visual mode
Hit % to match the other brace, selecting the whole rule
Hit J to join the lines
Try something like this:
:%s/{\n/{/g
:%s/;\n/;/g
:%s/{\s+/{/g
:%s/;\s+/;/g
This removes the newlines after opening braces and semicolons ('{' and ';') and then removes the extra whitespace between the concatenated lines.
If you want to change the file, go for rampion's solution.
If you don't want (or can't) change the file, you can play with a custom folding as it permits to choose what and how to display the folded text. For instance:
" {rtp}/fold/css-fold.vim
" [-- local settings --] {{{1
setlocal foldexpr=CssFold(v:lnum)
setlocal foldtext=CssFoldText()
let b:width1 = 20
let b:width2 = 15
nnoremap <buffer> + :let b:width2+=1<cr><c-l>
nnoremap <buffer> - :let b:width2-=1<cr><c-l>
" [-- global definitions --] {{{1
if exists('*CssFold')
setlocal foldmethod=expr
" finish
endif
function! CssFold(lnum)
let cline = getline(a:lnum)
if cline =~ '{\s*$'
return 'a1'
elseif cline =~ '}\s*$'
return 's1'
else
return '='
endif
endfunction
function! s:Complete(txt, width)
let length = strlen(a:txt)
if length > a:width
return a:txt
endif
return a:txt . repeat(' ', a:width - length)
endfunction
function! CssFoldText()
let lnum = v:foldstart
let txt = s:Complete(getline(lnum), b:width1)
let lnum += 1
while lnum < v:foldend
let add = s:Complete(substitute(getline(lnum), '^\s*\(\S\+\)\s*:\s*\(.\{-}\)\s*;\s*$', '\1: \2;', ''), b:width2)
if add !~ '^\s*$'
let txt .= ' ' . add
endif
let lnum += 1
endwhile
return txt. '}'
endfunction
I leave the sorting of the fields as exercise. Hint: get all the lines between v:foldstart+1 and v:voldend in a List, sort the list, build the string, and that's all.
I won’t answer the question directly, but instead I suggest you to reconsider your needs. I think that your “bad” example is in fact the better one. It is more readable, easier to modify and reason about. Good indentation is very important not only when it comes to programming languages, but also in CSS and HTML.
You mention that CSS rules are “taking up too many lines”. If you are worried about file size, you should consider using CSS and JS minifiers like YUI Compressor instead of making the code less readable.
A convenient way of doing this transformation is to run the following
short command:
:g/{/,/}/j
Go to the first line of the file, and use the command gqG to run the whole file through the formatter. Assuming runs of nonempty lines should be collapsed in the whole file.

Resources