I have for example a bunch of HTML pages like this :
<!DOCTYPE html>
<html>
<head><title>Table des matières</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<!-- 3,html,xhtml,charset="utf-8" -->
<meta name="src" content="content_final.tex" />
<link rel="stylesheet" type="text/css" href="content_final.css" />
<script type="text/javascript" src="./jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
$('div.caption span.id').each(function() { var result = $(this).text().replace(':','');
result=capitalizeFirstLetter(result);
$(this).text(result);
});
});
</script>
</head><body
>
<!--l. 125--><div class="crosslinks"><p class="noindent">[<a
href="chapter1.html" >next</a>] [tail] [<a
href="/sciences/index.html" >up</a>] </p></div>
<h2 class="likechapterHead"><a
id="x2-1000"></a>Table des matières</h2>
<div class="tableofcontents">
But impossible to convert all french accents in these HTML pages like above the accent in
"Table des matières" with "è" appearing instead of "è".
I tried 2 things :
for i in $(ls *.html); do iconv -f iso-8859-1 -t utf8 $i > $i"_new"; mv -f $i"_new" $i; done
=> the accents are not converted
for i in $(ls *.html); do recode ..html $i; done
=> I have the following errors :
recode: section5.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section6.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section7.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section8.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section9.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: table_of_contents.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
...
I don't know what to do to convert all these french accents ?
Has anyone got an idea or suggestion to convert all possible french accents ? I would like to use iconv, recode or sed commands.
UPDATE 1: taking a basic example, here is the message I get for a single file :
$ recode ..html table_of_contents.html
recode: table_of_contents.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
What's wrong ?
UPDATE 2: here is the output of my original HTML pages :
$file -i index.html
$ index.html: text/x-tex; charset=iso-8859-1
and the head of the index.html :
<!DOCTYPE html>
<html>
<head><title>Table des matières</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<!-- 3,html,xhtml,charset="utf-8" -->
<meta name="src" content="content_final.tex" />
<link rel="stylesheet" type="text/css" href="content_final.css" />
<script type="text/javascript" src="./jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
$('div.caption span.id').each(function() { var result = $(this).text().replace(':','');
result=capitalizeFirstLetter(result);
$(this).text(result);
If I apply the command :
$ recode -vfd u8..html index.html
Request: UTF-8..:libiconv:..ISO-10646-UCS-2..HTML_4.0
Shrunk to: UTF-8..ISO-10646-UCS-2..HTML_4.0
Recoding index.html... done
and
<!DOCTYPE html>
<html>
<head><title>Table des matires</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<!-- 3,html,xhtml,charset="utf-8" -->
<meta name="src" content="content_final.tex" />
<link rel="stylesheet" type="text/css" href="content_final.css" />
<script type="text/javascript" src="./jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
$('div.caption span.id').each(function() { var result = $(this).text().replace(':','');
result=capitalizeFirstLetter(result);
$(this).text(result);
});
});
</script>
as you can see, the "è" has disappeared.
What can I do ?
Assuming the source file encoding is UTF-8. Following command worked in my environment:
$ recode -vfd u8..html index.html
Output:
$ locale charmap
UTF-8
$ file -i index.html
index.html: text/html; charset=utf-8
$ recode -vfd u8..html index.html
Request: UTF-8..:iconv:..ISO-10646-UCS-2..HTML_4.0
Shrunk to: UTF-8..ISO-10646-UCS-2..HTML_4.0
Recoding index.html... done
You can use the command options to debug the error in this way:
-v Verbose output. Useful to find in which step the error occurred.
-f Forces the completion even if error occurred. You can compare the output file with original to figure out which character/location is giving trouble.
-d For HTML, recode doesn't convert ASCII characters. Avoids conversion of < > " & etc. html characters.
Update If the encoding/charset is iso-8859-1 then you need to use:
$ recode -vfd iso-8859-1..html index.html
Request: ISO-8859-1..ISO-10646-UCS-2..HTML_4.0
Recoding index.html... done
#Or use following.
$ recode -vfd lat1..html index.html
Request: ISO-8859-1..ISO-10646-UCS-2..HTML_4.0
Recoding index.html... done
The ISO-8859-1 has following aliases in recode:
l1
lat1
latin1
Latin-1
819/CR-LF
CP819/CR-LF
CSISOLATIN1
IBM819/CR-LF
ISO8859-1
iso-ir-100
ISO_8859-1
ISO_8859-1:1987
You can use anyone of the above in the command.
Related
I have a folder in a ftp with a hundred of subfolders, each have it's own index.html
I want to add a <link rel="stylesheet" href="https://subdomain.domain.fr/vad/client/build/iconfont.css">
in each index.html
The subdomain is variable and can be captured from another stylesheet link ex :
<link rel="stylesheet" href="https://subdomain.domain.fr/vad/client/build/theme.css">
I tried this :
find . -type f -name index.html -exec sed -i 's/<link rel="stylesheet" href="https:\/\/\(*\).domain.fr\/vad\/client\/build\/theme.css">/<link rel="stylesheet" href="https:\/\/\1.domain.fr\/vad\/client\/build\/theme.css"><link rel="stylesheet" href="https:\/\/\1.domain.fr\/vad\/client\/build\/iconfont.css">/g' {} \;
With capturing and copy groups but it's not working
For ease and readability, change the delimiter from / to let's say # You also have to escape real dots in search pattern…
sed -i 's#<link rel="stylesheet" href="https://\(*\)\.domain\.fr/vad/client/build/theme\.css">#<link rel="stylesheet" href="https://\1.domain.fr/vad/client/build/theme.css"><link rel="stylesheet" href="https://\1.domain.fr/vad/client/build/iconfont.css">#g'
From there, I can see there's a mistake in your regexp capturing group… You wrote \(*\), but I suspect you mean \(.*\) :) (otherwise, you where trying to capture nothing …or by chance opening parenthesis only…)
Now, it's look like you are replacing one word with another one, in order to change the CSS file? As it's appearing in a specific kind of line, you can perform a simple replacement in line matching that pattern ;)
sed -i '/\<link rel="stylesheet" href="https:\/\/.*\.domain\.fr\/vad\/client\/build/s#theme#iconfont#'
Using Perl and a Mojo::DOM HTML Parser to edit your HTML:
use strict; use warnings;
use Mojo::DOM;
# Slurp the whole HTML as string
my $html = join "", <>;
my $dom = Mojo::DOM->new($html);
# Fetch domain name
$_ = $dom
->find('link[href][rel="stylesheet"]')
->map(attr => 'href')
->last;
my ($domain) = m|^https?://([^/]+)/|
or die "No match https?!\n";
# Find/append
$dom
->find('head > link[href][rel="stylesheet"]')
->last
->append(
"\n" .
'<link rel="stylesheet" href="https://' .
$domain .
'/build/iconfont.css" />'
);
# Render
print "$dom";
Output
Example of one file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="fr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link href="https://subdomain.domain.fr/build/theme.css" rel="stylesheet">
<link href="https://subdomain.domain.fr/build/iconfont.css" rel="stylesheet">
<title></title>
</head>
<body>
POUET
</body>
</html>
Usage
First test the script against some files without sponge.
Then, if tests are satisfactory:
#!/bin/bash
shopt -s globstar # enable recursion **
for h in **/*.html; do
perl Mojo::DOM.pl "$h" | sponge "$h"
done
When loading the latest version of fbevents.js for Facebook Pixel the JSON global object is being overrided. I don't know why this is happening, but this broke some applications that was using the JSON implemented by MooTools (they add encode and decode to JSON global object). I did some tests and verified that the problem was introduced on version 2.9.42.
On the version 2.9.41 the problem don't occur.
The code for the test is below: (change the ID for yours)
You can change the fbevents version using the v param
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>Hello</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mootools/1.4.5/mootools-core-full-nocompat.js"></script>
<!-- Facebook Pixel Code -->
<script>
!(function (f, b, e, v, n, t, s) {
if (f.fbq) return;
n = f.fbq = function () {
n.callMethod
? n.callMethod.apply(n, arguments)
: n.queue.push(arguments);
};
if (!f._fbq) f._fbq = n;
n.push = n;
n.loaded = !0;
n.version = "2.0";
n.queue = [];
t = b.createElement(e);
t.async = !0;
t.src = v;
s = b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t, s);
})(
window,
document,
"script",
"https://connect.facebook.net/en_US/fbevents.js?v=2.9.42"
);
fbq("init", "YOUR_ID");
fbq("track", "PageView");
</script>
<noscript>
<img
height="1"
width="1"
src="https://www.facebook.com/tr?id=YOUR_ID&ev=PageView
&noscript=1"
/>
</noscript>
<script>
console.log("Version 2.9.42: ", JSON);
console.log("JSON before FB execute: ", JSON);
setTimeout(function () {
console.log("JSON after FB execute: ", JSON);
}, 3000);
</script>
</body>
</html>
I was researching on this and found something interesting.
The code inside fbevents.js didn't mess with the global scope, but another script was loaded, and this script is changing the global JSON.
The script is on this URL: https://connect.facebook.net/signals/config/1718502398417441?v=2.9.42&r=stable
You can open this and search for j.JSON=n. If you prettify the file, add spaces. It also adds JSON3 to the global scope. You can test typing window.JSON3.
See image for details:
That's my guess for now.
Edit 2:
You can also load different versions of this javascript file using the v parameter.
If you compare https://connect.facebook.net/signals/config/1718502398417441?v=2.9.41&r=stable and https://connect.facebook.net/signals/config/1718502398417441?v=2.9.42&r=stable
you can verify that the code on the image above was introduced on this version.
I am trying to implement my unity app for my Weebly site. I followed this tutorial: https://www.youtube.com/watch?v=mf-yNlMLcqA
I have these two codes:
1.
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | LearningEffective</title>
<script
src="https://pamaentertainment.weebly.com/files/theme/Build/UnityLoader.js">
</script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer",
"https://pamaentertainment.weebly.com/files/theme/Build/Learning Effective
online.json");
</script>
</head>
<body>
<div id="gameContainer" style="width: 720px; height: 1280px; margin: auto">
</div>
</body>
</html>
2.
{
"companyName": "pama",
"productName": "LearningEffective",
"dataUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.data.unityweb",
"asmCodeUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.code.unityweb",
"asmMemoryUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.memory.unityweb",
"asmFrameworkUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.framework.unityweb",
"TOTAL_MEMORY": 268435456,
"graphicsAPI": ["WebGL 2.0", "WebGL 1.0"],
"webglContextAttributes": {"preserveDrawingBuffer": false},
"backgroundUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.jpg",
"splashScreenStyle": "Dark",
"backgroundColor": "#FFFFFF"
}
When I try to load the page where Weebly's embed code is, Chrome pops up a window with this: Uncaught SyntaxError: Unexpected token < in JSON at position 0.
How can I fix this?
The URL you are using has a space. The correct URL doesn't have one.
Change this:
var gameInstance = UnityLoader.instantiate("gameContainer",
"https://pamaentertainment.weebly.com/files/theme/Build/Learning Effectiveonline.json");
To this:
var gameInstance = UnityLoader.instantiate("gameContainer",
"https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.json");
You need to set up a web server.
IIS - in file web.config:
<mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
<mimeMap fileExtension=".unityweb" mimeType="application/octet-stream" />
Apache - in file .htaccess:
AddType application/octet-stream unityweb
AddType application/json json
https://forum.unity.com/threads/webgl-uncaught-syntaxerror-unexpected-token-in-json-at-position-0.466784/
https://answers.unity.com/questions/1397472/webgl-build-when-uploaded-gives-me-this-error-unca.html
i have a problem with the phonegap app.
I try to connect with ajax post with simple php file which return my an array in my app.
This is simple example/tutorial from net. I try everything i read a tousends of topics, but i don't know where is problem.
My index of the phonegap app
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Minimal AppLaud App</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script type="text/javascript" charset="utf-8">
function connect(e)
{
var term= {button:e};
$.ajax({
url:'http://domain.pl/replay.php',
type:'POST',
data:term,
dataType:'json',
error:function(jqXHR,text_status,strError){
alert('no connection');},
timeout:6000,
success:function(data){
$("#result").html("");
for(var i in data){
$("#result").append("<li>"+data[i]+"</li>");
}
}
});}
</script>
</head>
<body id="stage" class="theme">
<center><b>Bikes or Cars</b></center>
<center><input onclick="connect(this.value)" type="button" value="cars" /></center>
<center><input onclick="connect(this.value)" type="button" value="bikes" /></center>
<center><b>Results</b></center>
<ul id="result"></ul>
</body>
</html>
And my replay.php file
<?php
$choice =$_POST["button"];
$cars = array("Honde", "BMW" , "Ferrari");
$bikes = array("Ducaite", "Royal Enfield" , "Harley Davidson");
if($choice == "cars") print json_encode($cars);
else print json_encode($bikes);
?>
I add domain whitelist to cordova and config xml files
<access origin=".*"/>
And i don't have any ideas what is wrong.
Thanks in advance for any suggestions.
Replace
<access origin=".*"/>
with
<access origin="*"/>
Maybe it will solve a problem.
I'm trying to make a audio player in Chrome with HTML5 and Javascript. But I got an error(file not readable) at the very beginning...
Below is my HTML code:
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>index</title>
<meta name="description" content="" />
<meta name="generator" content="Studio 3 http://aptana.com/" />
<meta name="author" content="liuuzyan" />
<!--<meta name="viewport" content="width=device-width; initial-scale=1.0" />-->
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="js/fun.js" type="text/javascript"></script>
</head>
<body>
<audio id="player" controls="controls">
Please use Firefox/Chrome/IE9 to browse this page.
</audio>
<input type="file" multiple="multiple" id="fileChose" />
</body>
And below is my Javascript code:
$(document).ready( function() {
$('#fileChose').change( function() {
var fileList=this.files;
for(var i=0;i<fileList.length;i++) {
var reader=new FileReader();
reader.onloaded=function(e){
$('#player').attr('src',e.target.result)
}
reader.onerror=function(e){
switch(e.target.error.code) {
case e.target.error.NOT_FOUND_ERR:
alert("file not found");
break;
case e.target.error.NOT_READABLE_ERR:
alert("file not readable");
break;
case e.target.error.ABORT_ERR:
alert("aborted");
break;
default:
alert('generic error?');
}
}
reader.readAsDataURL(fileList[i]);
}
});
});
Can anyone help me with this problem? Thanks a lot!
In Chrome you can add: --allow-file-access-from-files to the Chrome command line to allow local file to be read from local HTML pages.
You can also bundle your code up as Chrome Extension and get local file access that way.
Or upload the HTML files to a Server as already mentioned.